Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
i3-switcher
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pavel Kácha
i3-switcher
Commits
96b84fce
Commit
96b84fce
authored
9 years ago
by
pharook
Browse files
Options
Downloads
Patches
Plain Diff
Updated to take care of more batteries, no fixed paths
parent
7e649e75
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
i3-switcher.py
+58
-34
58 additions, 34 deletions
i3-switcher.py
with
58 additions
and
34 deletions
i3-switcher.py
+
58
−
34
View file @
96b84fce
...
...
@@ -7,6 +7,7 @@ import datetime
import
time
import
select
import
os.path
as
path
import
glob
from
operator
import
itemgetter
import
ipc
import
alsaaudio
...
...
@@ -65,42 +66,65 @@ def main(argv=None):
# But Pulse shifts Alsa Master, so this is good enough
# However, Pulse does not use Alsa mute knob, so that will
# work only on Alsa
mixer
=
alsaaudio
.
Mixer
()
mix_vol
=
mixer
.
getvolume
()[
0
]
mix_mute
=
bool
(
mixer
.
getmute
()[
0
])
mix_chars
=
u
"
▁▂▃▄▅▆▇█
"
mix_chars_scale
=
mix_vol
*
8
//
100
out
.
append
({
u
"
name
"
:
u
"
volume
"
,
u
"
full_text
"
:
u
"
♪%s
"
%
mix_chars
[
mix_chars_scale
],
u
"
color
"
:
u
"
#666666
"
if
mix_mute
else
u
"
#6666FF
"
})
# Battery
try
:
batt_sys_path
=
"
/sys/bus/acpi/drivers/battery/PNP0C0A:00/power_supply/BAT0
"
ac_sys_path
=
"
/sys/bus/acpi/drivers/ac/ACPI0003:00/power_supply/AC
"
batt_max
=
int
(
open
(
path
.
join
(
batt_sys_path
,
"
charge_full
"
),
"
r
"
).
read
())
batt_now
=
int
(
open
(
path
.
join
(
batt_sys_path
,
"
charge_now
"
),
"
r
"
).
read
())
batt_status
=
open
(
path
.
join
(
batt_sys_path
,
"
status
"
),
"
r
"
).
read
().
strip
()
ac_online
=
int
(
open
(
path
.
join
(
ac_sys_path
,
"
online
"
),
"
r
"
).
read
())
if
batt_status
==
"
Charging
"
:
batt_char
=
u
"
↑
"
elif
batt_status
==
"
Discharging
"
:
batt_char
=
u
"
↓
"
elif
batt_status
==
"
Full
"
:
batt_char
=
u
"
F
"
else
:
batt_char
=
u
"
"
batt_perc
=
100
*
batt_now
//
batt_max
batt_col
=
255
*
batt_now
//
batt_max
for
cardid
in
range
(
256
):
try
:
mixer
=
alsaaudio
.
Mixer
(
cardindex
=
cardid
)
if
mixer
:
break
except
alsaaudio
.
ALSAAudioError
:
mixer
=
None
if
mixer
:
mix_vol
=
mixer
.
getvolume
()[
0
]
mix_mute
=
bool
(
mixer
.
getmute
()[
0
])
mix_chars
=
u
"
▁▂▃▄▅▆▇█
"
mix_chars_scale
=
mix_vol
*
8
//
100
out
.
append
({
u
"
name
"
:
u
"
battery
"
,
u
"
full_text
"
:
u
"
%s%s%3s
"
%
(
u
"
↯
"
if
ac_online
else
u
"
"
,
batt_char
,
str
(
batt_perc
)
+
"
%
"
if
batt_status
!=
"
Full
"
else
"
ull
"
)
,
u
"
color
"
:
u
"
#
00FFFF
"
if
batt_status
==
"
Full
"
else
u
"
#%2x%2x%%00
"
%
(
255
-
batt_col
/
2
,
batt_col
)
u
"
name
"
:
u
"
volume
"
,
u
"
full_text
"
:
u
"
♪%s
"
%
mix_chars
[
mix_chars_scale
]
,
u
"
color
"
:
u
"
#
666666
"
if
mix_mute
else
u
"
#6666FF
"
})
except
IOError
:
pass
# Battery
for
ac_sys_path
in
glob
.
glob
(
"
/sys/bus/acpi/drivers/ac/*/power_supply/*
"
):
try
:
ac_online
=
int
(
open
(
path
.
join
(
ac_sys_path
,
"
online
"
),
"
r
"
).
read
())
if
ac_online
:
out
.
append
({
u
"
name
"
:
ac_sys_path
,
u
"
full_text
"
:
u
"
↯
"
,
u
"
color
"
:
u
"
#00FFFF
"
})
except
IOError
:
pass
for
batt_sys_path
in
glob
.
glob
(
"
/sys/bus/acpi/drivers/battery/*/power_supply/*
"
):
try
:
try
:
batt_max
=
int
(
open
(
path
.
join
(
batt_sys_path
,
"
charge_full
"
),
"
r
"
).
read
())
batt_now
=
int
(
open
(
path
.
join
(
batt_sys_path
,
"
charge_now
"
),
"
r
"
).
read
())
except
IOError
:
batt_max
=
int
(
open
(
path
.
join
(
batt_sys_path
,
"
energy_full
"
),
"
r
"
).
read
())
batt_now
=
int
(
open
(
path
.
join
(
batt_sys_path
,
"
energy_now
"
),
"
r
"
).
read
())
batt_status
=
open
(
path
.
join
(
batt_sys_path
,
"
status
"
),
"
r
"
).
read
().
strip
()
ac_online
=
int
(
open
(
path
.
join
(
ac_sys_path
,
"
online
"
),
"
r
"
).
read
())
if
batt_status
==
"
Charging
"
:
batt_char
=
u
"
↑
"
elif
batt_status
==
"
Discharging
"
:
batt_char
=
u
"
↓
"
elif
batt_status
==
"
Full
"
:
batt_char
=
u
""
else
:
batt_char
=
u
"
"
batt_perc
=
100
*
batt_now
//
batt_max
batt_col
=
255
*
batt_now
//
batt_max
battstr
=
u
"
%s%3s
"
%
(
batt_char
,
str
(
batt_perc
)
+
"
%
"
if
batt_status
!=
"
Full
"
else
"
Full
"
)
out
.
append
({
u
"
name
"
:
batt_sys_path
,
u
"
full_text
"
:
battstr
,
u
"
color
"
:
u
"
#00FFFF
"
if
batt_status
==
"
Full
"
else
u
"
#%2x%2x%%00
"
%
(
255
-
batt_col
/
2
,
batt_col
)
})
except
IOError
:
pass
# Date/time
out
.
append
({
"
name
"
:
"
datetime
"
,
"
full_text
"
:
datetime
.
datetime
.
now
().
strftime
(
"
%Y-%m-%d %H:%M:%S
"
),
"
short_text
"
:
"
short
"
,
"
color
"
:
"
%06x
"
%
color
})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment