-
Notifications
You must be signed in to change notification settings - Fork 3
/
i3-exit
executable file
·158 lines (132 loc) · 5.09 KB
/
i3-exit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python3
#for systems without systemd
#please install policykit to provide org.freedesktop.PolicyKit on AntiX
#updated for gtk3
# based on cb-exit used in CrunchBang Linux <http://crunchbanglinux.org/>
# modified by uranix 2012
# modified by DavDev aka ubuntupunk 2024
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
import os
import getpass
import time
prefix = '$HOME/.config/i3/scripts'
class i3_exit:
def disable_buttons(self):
self.cancel.set_sensitive(False)
self.logout.set_sensitive(False)
self.lock.set_sensitive(False)
self.suspend.set_sensitive(False)
self.hibernate.set_sensitive(False)
self.reboot.set_sensitive(False)
self.shutdown.set_sensitive(False)
def cancel_action(self,btn):
self.disable_buttons()
gtk.main_quit()
def logout_action(self,btn):
self.disable_buttons()
os.system(prefix + "i3-pre-exit")
os.system("i3-msg exit")
def lock_action(self,btn):
self.disable_buttons()
os.system(prefix + "i3-lock")
gtk.main_quit()
def suspend_action(self,btn):
self.disable_buttons()
os.system(prefix + "i3-lock")
os.system("dbus-send --system --print-reply \
--dest=\"org.freedesktop.UPower\" \
/org/freedesktop/UPower \
org.freedesktop.UPower.Suspend")
gtk.main_quit()
def hibernate_action(self,btn):
self.disable_buttons()
os.system(prefix + "i3-lock")
os.system("dbus-send --system --print-reply \
--dest=\"org.freedesktop.UPower\" \
/org/freedesktop/UPower \
org.freedesktop.UPower.Hibernate")
gtk.main_quit()
def reboot_action(self,btn):
self.disable_buttons()
os.system(prefix + 'i3-pre-exit')
os.system("dbus-send --system --print-reply \
--dest=\"org.freedesktop.ConsoleKit\" \
/org/freedesktop/ConsoleKit/Manager \
org.freedesktop.ConsoleKit.Manager.Restart")
def shutdown_action(self,btn):
self.disable_buttons()
os.system(prefix + 'i3-pre-exit')
os.system("dbus-send --system --print-reply \
--dest=\"org.freedesktop.ConsoleKit\" \
/org/freedesktop/ConsoleKit/Manager \
org.freedesktop.ConsoleKit.Manager.Stop")
def create_window(self):
self.window = gtk.Window()
title = "Log out " + getpass.getuser() + "?"
self.window.set_title(title)
self.window.set_border_width(5)
self.window.set_size_request(140, 250)
self.window.set_resizable(False)
self.window.set_keep_above(True)
self.window.stick()
self.window.set_position(1)
self.window.connect("delete_event", gtk.main_quit)
icon = Gtk.Image.new_from_stock(Gtk.STOCK_QUIT, Gtk.IconSize.MENU)
windowicon = icon.get_pixbuf()
self.window.set_icon(windowicon)
#Create HBox for buttons
self.button_box = gtk.VBox()
self.button_box.show()
#Cancel button
self.cancel = gtk.Button(stock = gtk.STOCK_CANCEL)
self.cancel.set_border_width(4)
self.cancel.connect("clicked", self.cancel_action)
self.button_box.pack_start(self.cancel)
self.cancel.show()
#Logout button
self.lock = gtk.Button("_Lock screen")
self.lock.set_border_width(4)
self.lock.connect("clicked", self.lock_action)
self.button_box.pack_start(self.lock)
self.lock.show()
#Logout button
self.logout = gtk.Button("Log _out")
self.logout.set_border_width(4)
self.logout.connect("clicked", self.logout_action)
self.button_box.pack_start(self.logout)
self.logout.show()
#Suspend button
self.suspend = gtk.Button("_Suspend")
self.suspend.set_border_width(4)
self.suspend.connect("clicked", self.suspend_action)
self.button_box.pack_start(self.suspend)
self.suspend.show()
#Hibernate button
self.hibernate = gtk.Button("_Hibernate")
self.hibernate.set_border_width(4)
self.hibernate.connect("clicked", self.hibernate_action)
self.button_box.pack_start(self.hibernate)
self.hibernate.show()
#Reboot button
self.reboot = gtk.Button("_Reboot")
self.reboot.set_border_width(4)
self.reboot.connect("clicked", self.reboot_action)
self.button_box.pack_start(self.reboot)
self.reboot.show()
#Shutdown button
self.shutdown = gtk.Button("_Power off")
self.shutdown.set_border_width(4)
self.shutdown.connect("clicked", self.shutdown_action)
self.button_box.pack_start(self.shutdown)
self.shutdown.show()
self.window.add(self.button_box)
self.window.show()
def __init__(self):
self.create_window()
def main():
gtk.main()
if __name__ == "__main__":
go = i3_exit()
main()