-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow_name
executable file
·191 lines (169 loc) · 5.82 KB
/
window_name
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env python3
import sys
import argparse
import time
import html
import threading
import i3ipc
parser = argparse.ArgumentParser()
parser.add_argument('--refresh-time', '-r', type=float, default=0.5, \
help='Interval for when to check data in seconds (float)')
parser.add_argument('--text-refresh-rate', '-R', type=float, default=1, \
help='Interval for text rotation:' \
'index will be increased by x for every r')
parser.add_argument('--string-length', '-l', type=int, default=25, \
help='Total length of printed string')
parser.add_argument('--pango', '-m', action='store_true', \
help='Enables printing with pango markup. ' \
' Required for some unicode symbols.')
parser.add_argument('--simple', '-s', action='store_true', \
help='Mode without a separate thread for text display')
parser.add_argument('--urgent-bg', type=str, \
default='#EF2F27', \
help='Background color for urgent windows')
parser.add_argument('--popup-bg', type=str, \
default='#FF9966', \
help='Background color for popup windows')
parser.add_argument('--floating-bg', type=str, \
default='#FF8700', \
help='Background color for floating windows')
#parser.add_argument('--unicode-font', type=str, \
# default='Font Awesome 5 Free Solid', \
# help='Font for drawing unicode symbols')
#parser.add_argument('--regular-font', type=str, \
# default='DejaVu Sans Mono', \
# help='Font for regular text')
args = parser.parse_args()
exit_flag = 0
index = 0.0
info_string = " " * args.string_length
program = ""
name = ""
floating = False
popup = False
urgent = False
class printThread(threading.Thread):
def __init__(self, threadID, name, counter):
threading.Thread.__init__(self)
self.ThreadID = threadID
self.name = name
self.counter = counter
self.daemon = True
def run(self):
print_thread(self.counter)
def print_thread(delay):
while True:
if exit_flag:
# printThread.exit()
return
time.sleep(delay)
print_info()
def print_info():
global index
global info_string
program_string = ("[%s]" % program) if len(str(program)) > 0 else ""
remaining_length = args.string_length - len(program_string)
if len(name) <= remaining_length - 2:
name_string = name.center(remaining_length, ' ')
index = 0.0
elif len(name) > remaining_length - 2 and args.simple:
dots = "\u2026"
name_string = name[:remaining_length - 3] + dots
name_string = name_string.center(remaining_length, ' ')
else:
index = (index + args.text_refresh_rate) % (len(name) + 4)
end = int(index) + remaining_length - 3
name_string = name + " ++ " + name
name_string = name_string[int(index):end]
name_string = name_string.center(remaining_length, ' ')
if args.pango:
program_string = html.escape(program_string, quote=True)
name_string = html.escape(name_string, quote=True)
if urgent:
info_string = \
'<span foreground="#FFFFFF" ' \
'background="%s' \
'<b>%s</b><i>%s</i></span>' % (args.urgent_bg, program_string, name_string)
elif popup:
info_string = \
'<span foreground="#000000" ' \
'background="%s">' \
'<b>%s</b><i>%s</i></span>' % (args.popup_bg, program_string, name_string)
elif floating:
info_string = \
'<span foreground="#000000" ' \
'background="%s">' \
'<b>%s</b><i>%s</i></span>' % (args.floating_bg, program_string, name_string)
else:
info_string = '<span><b>%s</b><i>%s</i></span>' % (program_string, name_string)
else:
info_string = program_string + name_string
print(info_string)
sys.stdout.flush()
def on_window_focus(i3, e):
focused = i3.get_tree().find_focused()
set_info_string(focused)
def on_workspace_focus(self, e):
if e.current:
try:
w = e.find_focused()
set_info_string(w)
except:
set_info_string(None)
def set_info_string(window):
global name
global program
global floating
global popup
global urgent
if window is None or window.type == 'workspace':
name = ''
program = ''
floating = False
popup = False
urgent = False
else:
floating = False
popup = False
urgent = window.urgent
if "on" in window.floating:
floating = True
if window.window_role == "pop-up":
popup = True
program = window.window_class
name = str(window.name)
if args.simple:
print_info()
try:
i3 = i3ipc.Connection()
focused = i3.get_tree().find_focused()
set_info_string(focused)
i3.on('window::focus', on_window_focus)
i3.on('window::title', on_window_focus)
i3.on('window::floating', on_window_focus)
i3.on('window::urgent', on_window_focus)
i3.on('window::close', on_window_focus)
i3.on('workspace::focus', on_workspace_focus)
if not args.simple:
thread1 = printThread(1, "Thread-1", args.refresh_time)
thread1.start()
i3.main()
if not args.simple:
thread1.join()
except Exception as e:
import gi
gi.require_version('Notify', '0.7')
from gi.repository import Notify
Notify.init("window_name:exception")
import traceback
strace = traceback.format_exc()
notification = Notify.Notification.new("window_name exception", str(e) + "\n\n" + strace)
notification.set_urgency(Notify.Urgency.CRITICAL)
notification.show()
Notify.uninit()
#print(e)
#print("Unexpected error:", sys.exc_info()[0])
#exit_flag = 1
finally:
exit_flag = 1
i3.main_quit()