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
d02b8ee7
Commit
d02b8ee7
authored
9 years ago
by
pharook
Browse files
Options
Downloads
Patches
Plain Diff
Battery warning and poweroff
parent
32bdb85f
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
+15
-0
15 additions, 0 deletions
i3-switcher.py
with
15 additions
and
0 deletions
i3-switcher.py
+
15
−
0
View file @
d02b8ee7
...
...
@@ -7,11 +7,15 @@ import datetime
import
time
import
select
import
os.path
as
path
import
os
import
glob
from
operator
import
itemgetter
import
ipc
import
alsaaudio
import
subprocess
battery_warn
=
5
battery_poweroff
=
3
def
jout
(
d
):
sys
.
stdout
.
write
(
"
,
"
)
...
...
@@ -46,6 +50,8 @@ def main(argv=None):
sys
.
stderr
=
open
(
path
.
join
(
path
.
expanduser
(
"
~
"
),
"
i3-switcher.stderr
"
),
"
a
"
)
debug
(
"
Started
"
)
color
=
0x00FF00
last_batt_perc
=
100
DEVNULL
=
os
.
open
(
os
.
devnull
,
os
.
O_RDWR
)
while
True
:
# Windows
clients
=
ipc
.
getwin
(
i3command
.
command
(
ipc
.
TREE
))
...
...
@@ -97,6 +103,7 @@ def main(argv=None):
except
IOError
:
pass
batt_percs
=
[]
for
batt_sys_path
in
glob
.
glob
(
"
/sys/bus/acpi/drivers/battery/*/power_supply/*
"
):
try
:
try
:
...
...
@@ -116,6 +123,7 @@ def main(argv=None):
else
:
batt_char
=
u
"
"
batt_perc
=
100
*
batt_now
//
batt_max
batt_percs
.
append
(
batt_perc
)
batt_col
=
255
*
batt_now
//
batt_max
battstr
=
u
"
%s%3s
"
%
(
batt_char
,
str
(
batt_perc
)
+
"
%
"
if
batt_status
!=
"
Full
"
else
"
Full
"
)
out
.
append
({
...
...
@@ -126,6 +134,13 @@ def main(argv=None):
except
IOError
:
pass
batt_perc_overall
=
max
(
batt_percs
)
if
batt_perc_overall
<=
battery_warn
and
int
(
batt_perc_overall
)
<
int
(
last_batt_perc
):
last_batt_perc
=
batt_perc_overall
subprocess
.
call
([
"
i3-nagbar
"
,
"
-m
"
,
"
Battery low (%s)
"
%
"
,
"
.
join
(
"
%s%%
"
%
p
for
p
in
batt_percs
)],
stdin
=
DEVNULL
,
stdout
=
DEVNULL
)
if
batt_perc_overall
<=
battery_poweroff
:
subprocess
.
call
([
"
/usr/sbin/poweroff
"
],
stdin
=
DEVNULL
,
stdout
=
DEVNULL
)
# Date/time
out
.
append
({
"
name
"
:
"
datetime
"
,
"
full_text
"
:
datetime
.
datetime
.
now
().
strftime
(
"
%Y-%m-%d %H:%M:%S
"
),
"
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