Skip to content

Commit

Permalink
Deprecate qtile_extras.bar.Bar
Browse files Browse the repository at this point in the history
All features of this bar have been incorporated in the main
libqtile library so there is no need to maintain it here.

To avoid breakages, users can still import the bar but will
get a warning telling them that they should be using
libqtile.bar.Bar from now on.
  • Loading branch information
elParaguayo committed Feb 20, 2022
1 parent c5fd56a commit c034261
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 455 deletions.
3 changes: 0 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ There's a :ref:`mixin <tooltip-mixin>` if you want to add tooltips to widgets.
I've also added some "eye candy" in the form of:

- :ref:`Widget Decorations <widget-decorations>`
- :ref:`Bar Borders <bar-borders>`
- :ref:`Wallpapers <wallpapers>`

Lastly, I've created a new ``ImgMask`` class which, rather than drawing the source image,
Expand Down Expand Up @@ -53,7 +52,6 @@ without needing to recrate the icons themselves. You can see the class :ref:`her
manual/install
manual/how_to/popup
manual/how_to/decorations
manual/how_to/bar
manual/how_to/img-mask
manual/how_to/tooltips

Expand All @@ -65,7 +63,6 @@ without needing to recrate the icons themselves. You can see the class :ref:`her
manual/ref/widgets
manual/ref/popup
manual/ref/decorations
manual/ref/bar
manual/ref/imgmask

.. toctree::
Expand Down
79 changes: 0 additions & 79 deletions docs/manual/how_to/bar.rst

This file was deleted.

10 changes: 0 additions & 10 deletions docs/manual/ref/bar.rst

This file was deleted.

221 changes: 5 additions & 216 deletions qtile_extras/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,224 +19,13 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import libqtile.bar
from libqtile.utils import has_transparency
from libqtile.log_utils import logger


class Bar(libqtile.bar.Bar):
"""
A modded version of the bar, which can display a border around it.
"""

_experimental = True

defaults = [
("border_color", "#000000", "Border colour as str or list of str [N E S W]"),
("border_width", 0, "Width of border as int or list of ints [N E S W]"),
]

_screenshots = [("bar.png", "")]

def __init__(self, widgets, size, **config):
libqtile.bar.Bar.__init__(self, widgets, size, **config)
self.add_defaults(Bar.defaults)

if isinstance(self.margin, int):
self.margin = [self.margin] * 4

if isinstance(self.border_width, int):
self.border_width = [self.border_width] * 4

def _configure(self, qtile, screen):
libqtile.bar.Gap._configure(self, qtile, screen)

if sum(self.margin) or sum(self.border_width):

if isinstance(self.border_color, str):
self.border_color = [self.border_color] * 4

# 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 for m, b in zip(self.margin, self.border_width)]

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])

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, 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.drawer = self.window.create_drawer(width, 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 _actual_draw(self):
self.queued_draws = 0
self._resize(self.length, self.widgets)

# We draw the border before the widgets
if self.border_width:

# The border is drawn "outside" of the bar (i.e. not in the space that the
# widgets occupy) so we need to add the additional space
width = self.width + self.border_width[1] + self.border_width[3]
height = self.height + self.border_width[0] + self.border_width[2]

# line_opts is a list of tuples where each tuple represents the borders
# in the order N, E, S, W. The border tuple contains two pairs of
# co-ordinates for the start and end of the border.
line_opts = [
((0, self.border_width[0] * 0.5), (width, self.border_width[0] * 0.5)),
(
(width - (self.border_width[1] * 0.5), self.border_width[0]),
(width - (self.border_width[1] * 0.5), height - self.border_width[2]),
),
(
(0, height - self.border_width[2] + (self.border_width[2] * 0.5)),
(width, height - self.border_width[2] + (self.border_width[2] * 0.5)),
),
(
(self.border_width[3] * 0.5, self.border_width[0]),
(self.border_width[3] * 0.5, height - self.border_width[2]),
),
]

self.drawer.clear(self.background)

for border_width, colour, opts in zip(
self.border_width, self.border_color, line_opts
):

if not border_width:
continue

move_to, line_to = opts

# Draw the border
self.drawer.set_source_rgb(colour)
self.drawer.ctx.set_line_width(border_width)
self.drawer.ctx.move_to(*move_to)
self.drawer.ctx.line_to(*line_to)
self.drawer.ctx.stroke()

self.drawer.draw(0, 0)

for i in self.widgets:
i.draw()
end = i.offset + i.length # pylint: disable=undefined-loop-variable
# we verified that self.widgets is not empty in self.draw(), see above.
if end < self.length:
if self.horizontal:
self.drawer.draw(offsetx=end, width=self.length - end)
else:
self.drawer.draw(offsety=end, height=self.length - end)


def inject_bar_border(classdef):
@property
def width(self):
if self.bar.horizontal:
return self.length
return self.bar.width

@property
def height(self):
if self.bar.horizontal:
return self.bar.height
return self.length

def _offset_draw(self, offsetx=0, offsety=0, width=None, height=None):
if self.bar.horizontal:
self._realdraw(offsetx=offsetx, offsety=self.offsety, width=width, height=height)
else:
self._realdraw(offsetx=self.offsetx, offsety=offsety, width=width, height=height)

def _configure(self, qtile, bar):
self._old_bar_configure(qtile, bar)
self._realdraw = self.drawer.draw
self.drawer.draw = self._offset_draw

if not hasattr(classdef, "_injected_offsets"):

classdef._offset_draw = _offset_draw
classdef._old_bar_configure = classdef._configure
classdef._configure = _configure
classdef._injected_offsets = True
classdef.height = height
classdef.width = width
logger.warning(
"There is no longer a need to use qtile_extras.bar.Bar. "
"Please update your config to use libqtile.bar.Bar."
)
4 changes: 0 additions & 4 deletions qtile_extras/widget/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from libqtile.widget import widgets as qtile_widgets
from libqtile.widget.import_error import make_error

from qtile_extras.bar import inject_bar_border
from qtile_extras.widget.decorations import inject_decorations

widgets = {
Expand Down Expand Up @@ -58,9 +57,6 @@ def modify(classdef, *args, initialise=True, **config):
# Inject the decorations code into the widget
inject_decorations(classdef)

# Inject code to position widgets when there are borders
inject_bar_border(classdef)

if initialise:
return classdef(*args, **config)

Expand Down
Loading

0 comments on commit c034261

Please sign in to comment.