Skip to content

Commit a5a27e7

Browse files
committed
Fixes to the flash color of the portals.
1 parent d18ddd9 commit a5a27e7

File tree

1 file changed

+35
-21
lines changed

1 file changed

+35
-21
lines changed

src/petronia/shell/view/portal_chrome.py

+35-21
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ def __init__(self, portal_id, bus, pos_x, pos_y, width, height, manager):
4343
# Make configuration better
4444
self.color_1 = 0
4545
self.color_2 = 0
46+
self.color_1f = 0x202020
47+
self.color_2f = 0x202020
48+
self._flashing = False
49+
self._use_flash_color = False
4650
self.accent_width = 64
4751

4852
left, right, top, bottom = manager.get_chrome_size(pos_x, pos_y, width, height)
@@ -69,23 +73,29 @@ def set_portal_size(self, pos_x, pos_y, width, height):
6973
self.move_resize(left, top, right - left, bottom - top, self._is_active)
7074

7175
def _on_paint(self, hwnd, hdc, width, height):
72-
self._draw_rect(hdc, 0, 0, width, height, self.color_1)
76+
c1 = self.color_1
77+
c2 = self.color_2
78+
if self._use_flash_color:
79+
c1 = self.color_1f
80+
c2 = self.color_2f
81+
self._log_debug("Using colors #{0} #{1}".format(hex(c1), hex(c2)))
82+
self._draw_rect(hdc, 0, 0, width, height, c1)
7383
if width >= self.accent_width * 3:
7484
if height >= self.accent_width * 3:
7585
# 4 corners of color
76-
self._draw_rect(hdc, 0, 0, self.accent_width, self.accent_width, self.color_2)
77-
self._draw_rect(hdc, width - self.accent_width, 0, self.accent_width, self.accent_width, self.color_2)
78-
self._draw_rect(hdc, 0, height - self.accent_width, self.accent_width, self.accent_width, self.color_2)
86+
self._draw_rect(hdc, 0, 0, self.accent_width, self.accent_width, c2)
87+
self._draw_rect(hdc, width - self.accent_width, 0, self.accent_width, self.accent_width, c2)
88+
self._draw_rect(hdc, 0, height - self.accent_width, self.accent_width, self.accent_width, c2)
7989
self._draw_rect(hdc, width - self.accent_width, height - self.accent_width, self.accent_width,
80-
self.accent_width, self.color_2)
90+
self.accent_width, c2)
8191
else:
8292
# Vertical bars of color
83-
self._draw_rect(hdc, 0, 0, self.accent_width, height, self.color_2)
84-
self._draw_rect(hdc, width - self.accent_width, 0, self.accent_width, height, self.color_2)
93+
self._draw_rect(hdc, 0, 0, self.accent_width, height, c2)
94+
self._draw_rect(hdc, width - self.accent_width, 0, self.accent_width, height, c2)
8595
elif height >= self.accent_width * 3:
8696
# Horizontal bars of color
87-
self._draw_rect(hdc, 0, 0, width, self.accent_width, self.color_2)
88-
self._draw_rect(hdc, 0, height - self.accent_width, width, self.accent_width, self.color_2)
97+
self._draw_rect(hdc, 0, 0, width, self.accent_width, c2)
98+
self._draw_rect(hdc, 0, height - self.accent_width, width, self.accent_width, c2)
8999

90100
# noinspection PyUnusedLocal
91101
def _on_portal_removed(self, event_id, target_id, event_obj):
@@ -108,21 +118,19 @@ def _on_border_size_change(self, event_id, target_id, event_obj):
108118

109119
# noinspection PyUnusedLocal
110120
def _on_portal_flashing(self, event_id, target_id, event_obj):
111-
self._log_verbose("Flashing portal chrome {0}".format(self.cid))
112-
color_c1 = self.color_1
113-
color_c2 = self.color_2
114-
color_f1 = _brighten_color(self.color_1)
115-
color_f2 = _brighten_color(self.color_2)
121+
self._log_debug("Flashing portal chrome {0}".format(self.cid))
116122

117123
def flash():
118124
# Just flash once. Windows will send a message if another flash is required.
119-
self.color_1 = color_f1
120-
self.color_2 = color_f2
125+
if self._flashing:
126+
return
127+
self._flashing = True
128+
self._use_flash_color = True
121129
self.draw()
122130
time.sleep(self._manager.flash_time)
123-
self.color_1 = color_c1
124-
self.color_2 = color_c2
131+
self._use_flash_color = False
125132
self.draw()
133+
self._flashing = False
126134

127135
threading.Thread(
128136
target=flash,
@@ -143,6 +151,8 @@ def _on_portal_activated(self, event_id, target_id, event_obj):
143151
height = portal_size['height']
144152

145153
self.color_1, self.color_2 = self._manager.active_colors
154+
self.color_1f = _brighten_color(self.color_1)
155+
self.color_2f = _brighten_color(self.color_2)
146156
self.set_portal_size(pos_x, pos_y, width, height)
147157
self.draw()
148158

@@ -160,6 +170,8 @@ def _on_portal_deactivated(self, event_id, target_id, event_obj):
160170
height = portal_size['height']
161171

162172
self.color_1, self.color_2 = self._manager.inactive_colors
173+
self.color_1f = _brighten_color(self.color_1)
174+
self.color_2f = _brighten_color(self.color_2)
163175
self.set_portal_size(pos_x, pos_y, width, height)
164176
self.draw()
165177

@@ -169,7 +181,7 @@ def _brighten_color(c):
169181
r = (c >> 16) & 0xff
170182
g = (c >> 8) & 0xff
171183
b = c & 0xff
172-
return ((max(0xff, r << 1) << 16) & 0xff0000) | ((max(0xff, g << 1) << 8) & 0xff00) | (max(0xff, b << 1) & 0xff)
184+
return ((min(0xff, r << 1) << 16) & 0xff0000) | ((min(0xff, g << 1) << 8) & 0xff00) | (min(0xff, b << 1) & 0xff)
173185

174186

175187
def _darken_color(c):
@@ -199,8 +211,8 @@ def __init__(self, bus, config):
199211
self._inactive_color2 = 0x404040
200212
self._position = 'bottom'
201213
self._width = 10
202-
self.flash_time = 1.2
203-
self.flash_count = 3
214+
self.flash_time = 0.8
215+
self.flash_count = 3 # FIXME remove
204216
self.update_border()
205217

206218
@property
@@ -287,5 +299,7 @@ def _on_portal_resized(self, event_id, target_id, event_obj):
287299
gui = _PortalGuiWindow(target_id, self._bus, pos_x, pos_y, width, height, self)
288300
gui.color_1 = self._inactive_color1
289301
gui.color_2 = self._inactive_color2
302+
gui.color_1f = _brighten_color(self._inactive_color1)
303+
gui.color_2f = _brighten_color(self._inactive_color2)
290304
# TODO setup flash
291305
self.__portal_map[target_id]['gui'] = gui

0 commit comments

Comments
 (0)