def test_has_transparency(): colours = [ ("#00000000", True), ("#000000ff", False), ("#ff00ff.5", True), ((255, 255, 255, 0.5), True), ((255, 255, 255), False), (["#000000", "#ffffff"], False), (["#000000", "#ffffffaa"], True) ] for colour, expected in colours: assert utils.has_transparency(colour) == expected
def _configure(self, qtile, screen): Gap._configure(self, qtile, screen) if self.margin: if isinstance(self.margin, int): self.margin = [self.margin] * 4 if self.horizontal: self.x += self.margin[3] self.width -= self.margin[1] + self.margin[3] self.length = self.width if self.size == self.initial_size: self.size += self.margin[0] + self.margin[2] if self.screen.top is self: self.y += self.margin[0] else: self.y -= self.margin[2] else: self.y += self.margin[0] self.height -= self.margin[0] + self.margin[2] self.length = self.height self.size += self.margin[1] + self.margin[3] if self.screen.left is self: self.x += self.margin[3] else: self.x -= self.margin[1] for w in self.widgets: # Executing _test_orientation_compatibility later, for example in # the _configure() method of each widget, would still pass # test/test_bar.py but a segfault would be raised when nosetests is # about to exit w._test_orientation_compatibility(self.horizontal) if self.window: # We get _configure()-ed with an existing window when screens are getting # reconfigured but this screen is present both before and after self.window.place(self.x, self.y, self.width, self.height, 0, None) else: # Whereas we won't have a window if we're startup up for the first time or # the window has been killed by us no longer using the bar's screen # X11 only: # To preserve correct display of SysTray widget, we need a 24-bit # window where the user requests an opaque bar. if self.qtile.core.name == "x11": depth = 32 if has_transparency( self.background ) else self.qtile.core.conn.default_screen.root_depth self.window = self.qtile.core.create_internal( self.x, self.y, self.width, self.height, depth) else: self.window = self.qtile.core.create_internal( self.x, self.y, self.width, self.height) self.window.opacity = self.opacity self.window.unhide() self.drawer = self.window.create_drawer(self.width, self.height) self.drawer.clear(self.background) self.window.process_window_expose = self.draw self.window.process_button_click = self.process_button_click self.window.process_button_release = self.process_button_release self.window.process_pointer_enter = self.process_pointer_enter self.window.process_pointer_leave = self.process_pointer_leave self.window.process_pointer_motion = self.process_pointer_motion self.window.process_key_press = self.process_key_press self.crashed_widgets = [] if self._configured: for i in self.widgets: self._configure_widget(i) else: for idx, i in enumerate(self.widgets): if i.configured: i = i.create_mirror() self.widgets[idx] = i success = self._configure_widget(i) if success: qtile.register_widget(i) self._remove_crashed_widgets() self.draw() self._resize(self.length, self.widgets) self._configured = True
def set_source_rgb(self, colour, ctx=None): # Remove transparency from non-32 bit windows if utils.has_transparency(colour) and self._depth != 32: colour = utils.remove_transparency(colour) base.Drawer.set_source_rgb(self, colour, ctx)
def _configure(self, qtile, screen): # We only want to adjust margin sizes once unless there's a new strut if not self._configured or self._add_strut: Gap._configure(self, qtile, screen) self._borders_drawn = False if sum(self._initial_margin) or sum( self.border_width) or self._add_strut: try: # Check if colours are valid but don't convert to rgba here if isinstance(self.border_color, list) and len( self.border_color) == 4: [rgb(col) for col in self.border_color] else: rgb(self.border_color) self.border_color = [self.border_color] * 4 except (ValueError, TypeError): logger.warning( "Invalid border_color specified. Borders will not be displayed." ) self.border_width = [0, 0, 0, 0] # Increase the margin size for the border. The border will be drawn # in this space so the empty space will just be the margin. self.margin = [ m + b + s for m, b, s in zip( self._initial_margin, self.border_width, self.struts) ] if self.horizontal: self.x += self.margin[3] - self.border_width[3] self.width -= self.margin[1] + self.margin[3] self.length = self.width if self.size == self.initial_size: self.size += self.margin[0] + self.margin[2] if self.screen.top is self: self.y += self.margin[0] - self.border_width[0] else: self.y -= self.margin[2] + self.border_width[2] else: self.y += self.margin[0] - self.border_width[0] self.height -= self.margin[0] + self.margin[2] self.length = self.height self.size += self.margin[1] + self.margin[3] if self.screen.left is self: self.x += self.margin[3] else: self.x -= self.margin[1] width = self.width + (self.border_width[1] + self.border_width[3]) height = self.height + (self.border_width[0] + self.border_width[2]) if self.window: # We get _configure()-ed with an existing window when screens are getting # reconfigured but this screen is present both before and after self.window.place(self.x, self.y, width, height, 0, None) else: # Whereas we won't have a window if we're startup up for the first time or # the window has been killed by us no longer using the bar's screen # X11 only: # To preserve correct display of SysTray widget, we need a 24-bit # window where the user requests an opaque bar. if self.qtile.core.name == "x11": depth = (32 if has_transparency(self.background) else self.qtile.core.conn.default_screen.root_depth) self.window = self.qtile.core.create_internal( self.x, self.y, width, height, depth) else: self.window = self.qtile.core.create_internal( self.x, self.y, width, height) self.window.opacity = self.opacity self.window.unhide() self.window.process_window_expose = self.process_window_expose self.window.process_button_click = self.process_button_click self.window.process_button_release = self.process_button_release self.window.process_pointer_enter = self.process_pointer_enter self.window.process_pointer_leave = self.process_pointer_leave self.window.process_pointer_motion = self.process_pointer_motion self.window.process_key_press = self.process_key_press # We create a new drawer even if there's already a window to ensure the # drawer is the right size. self.drawer = self.window.create_drawer(width, height) self.drawer.clear(self.background) self.crashed_widgets = [] if self._configured: for i in self.widgets: self._configure_widget(i) else: for idx, i in enumerate(self.widgets): # Create a mirror if this widget is being placed on a different bar # We don't do isinstance(i, Mirror) because importing Mirror (at the top) # would give a circular import as libqtile.widget.base imports lbqtile.bar if i.configured and i.bar != self and i.__class__.__name__ != "Mirror": i = i.create_mirror() self.widgets[idx] = i success = self._configure_widget(i) if success: qtile.register_widget(i) self._remove_crashed_widgets() self.draw() self._resize(self.length, self.widgets) self._configured = True self._add_strut = False