-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup_icons.py
179 lines (141 loc) · 7.14 KB
/
group_icons.py
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
import os
import cairocffi
from xdg.IconTheme import getIconPath
from libqtile import hook, bar
from libqtile.images import Img
from libqtile.widget import base
from libqtile.lazy import lazy
from .icon_utils import _get_class_icon, _get_theme_icon, _get_fallback_icon, _get_custom_icon, get_window_icon
from .mouse_callbacks import *
from .defaults import DEFAULTS
class GroupTaskList(base._Widget, base.PaddingMixin, base.MarginMixin):
defaults = DEFAULTS
def __init__(self, group_name=None, **config):
base._Widget.__init__(self, length=bar.CALCULATED, **config)
self.add_defaults(GroupTaskList.defaults)
self.add_defaults(base.PaddingMixin.defaults)
self.add_defaults(base.MarginMixin.defaults)
self.icon_size = self.icon_size
self.icon_spacing_left = self.icon_spacing_left
self.icon_spacing_right = self.icon_spacing_right
self.icon_alignment = self.icon_alignment # Alinhamento dos ícones
self._icons_cache = {}
self.group_name = group_name
self.scroll_groups = self.scroll_groups
self.clicked_window = None
def _configure(self, qtile, bar):
base._Widget._configure(self, qtile, bar)
if self.fontsize is None:
calc = self.bar.height - self.margin_y * 2 - self.borderwidth * 2 - self.padding_y * 2
self.fontsize = max(calc, 1)
self.drawer = self.bar.window.create_drawer(self.bar.width, self.bar.height)
self.layout = self.drawer.textlayout(
"", self.fontcolor, self.font, self.fontsize, None, markup=False
)
self.setup_hooks()
def calculate_length(self):
if self.group_name is None or self.group_name not in self.qtile.groups_map:
return 0
group = self.qtile.groups_map[self.group_name]
icon_count = len(group.windows)
text_layout = self.drawer.textlayout(self.group_name, self.fontcolor, self.font, self.fontsize, None)
total_width = text_layout.width + icon_count * (self.icon_size + self.icon_spacing_left + self.icon_spacing_right) + self.padding_left + self.padding_right
if total_width > self.max_width:
total_width = self.max_width
elif total_width < self.min_width:
total_width = self.min_width
return total_width
def get_window_icon(self, window):
return get_window_icon(window, self.theme_mode, self.theme_path, self.fallback_icon, self.icon_size, self._icons_cache)
def draw_icon(self, surface, offset):
if not surface:
return
x = offset + (self.icon_size // 2)
y = (self.bar.height - self.icon_size) // 2
self.drawer.ctx.save()
self.drawer.ctx.translate(x, y)
self.drawer.ctx.set_source(surface)
self.drawer.ctx.paint()
self.drawer.ctx.restore()
def draw_line(self, offset, window):
x_start = offset + (self.icon_size // 2) - (self.line_thickness_active // 2)
y = (self.bar.height + self.icon_size) // 2 + self.line_offset
if window.minimized:
color = self.line_color_minimized
thickness = self.line_thickness_minimized
elif window.floating:
color = self.line_color_floating
thickness = self.line_thickness_floating
elif window == self.qtile.current_window:
color = self.line_color_active
thickness = self.line_thickness_active
else:
color = self.line_color_inactive
thickness = self.line_thickness_inactive
# return
self.drawer.set_source_rgb(color)
self.drawer.ctx.set_line_width(thickness)
self.drawer.ctx.move_to(x_start, y)
self.drawer.ctx.line_to(x_start + self.icon_size, y)
self.drawer.ctx.stroke()
def draw(self):
if self.group_name is None or self.group_name not in self.qtile.groups_map:
return
group = self.qtile.groups_map[self.group_name]
if not group.windows and group.screen and group == self.qtile.current_group:
background = self.background_active
elif group.windows:
if group.screen:
background = self.background_active
else:
background = self.background_inactive
else:
background = self.background_empty
self.drawer.clear(background)
offset = self.padding_left
group_text = self.group_name
if self.label_visibility != "None" and (self.label_visibility == "Always" or (self.label_visibility == "Empty" and not group.windows)):
text_layout = self.drawer.textlayout(group_text, self.fontcolor, self.font, self.fontsize, None)
if self.label_visibility == "Empty" and self.label_position == "Center":
offset = (self.calculate_length() - text_layout.width) // 2
else:
offset = self.padding_left
text_layout.draw(offset, (self.bar.height - self.fontsize) // 2)
offset += text_layout.width + self.margin_x
# Calcula o offset inicial baseado no alinhamento dos ícones
icon_total_width = len(group.windows) * (self.icon_size + self.icon_spacing_left + self.icon_spacing_right) - self.icon_spacing_right
if self.icon_alignment == "center":
offset += (self.calculate_length() - icon_total_width) // 2 - (self.icon_size // 2)
elif self.icon_alignment == "right":
offset += self.calculate_length() - icon_total_width - self.padding_right - (self.icon_size // 2)
self._box_positions = [] # Modificado para armazenar as posições iniciais e finais
for window in group.windows:
icon = self.get_window_icon(window)
if icon:
start_position = offset
self.draw_icon(icon, start_position)
self.draw_line(start_position, window) # Desenhar a linha sob o ícone
end_position = start_position + self.icon_size
self._box_positions.append((start_position, end_position))
offset += self.icon_size + self.icon_spacing_right + self.icon_spacing_left
total_width = offset + self.padding_right
if total_width > self.max_width:
total_width = self.max_width
elif total_width < self.min_width:
total_width = self.min_width
self.drawer.draw(offsetx=self.offsetx, offsety=self.offsety, width=total_width)
def button_press(self, x, y, button):
button_press(self, x, y, button)
def _hook_response(self, *args, **kwargs):
self._icons_cache.clear() # Clear the cache to force icon updates
self.draw()
self.bar.draw()
def setup_hooks(self):
hook.subscribe.client_managed(self._hook_response)
hook.subscribe.client_urgent_hint_changed(self._hook_response)
hook.subscribe.client_killed(self._hook_response)
hook.subscribe.setgroup(self._hook_response)
hook.subscribe.group_window_add(self._hook_response)
hook.subscribe.current_screen_change(self._hook_response)
hook.subscribe.changegroup(self._hook_response)
hook.subscribe.client_focus(self._hook_response)