Skip to content

Commit

Permalink
Clean-ups to GroupBox line highlighting
Browse files Browse the repository at this point in the history
- Remove line_thickness option, use borderwidth instead
- Remove bar_height handling, instead set the padding of the TextFrame
  correctly
- Only add the highlighting if the group is actually highlighted

Closes #791

Fixes #790
  • Loading branch information
flacjacket committed Oct 30, 2015
1 parent 848b2cc commit b18fed4
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 81 deletions.
48 changes: 16 additions & 32 deletions libqtile/drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,17 @@ def draw(self, x, y):
self.drawer.ctx.move_to(x, y)
self.drawer.ctx.show_layout(self.layout)

def framed(self, border_width, border_color, pad_x, pad_y,
highlight_color=None, line_thickness=None):
return TextFrame(self, border_width, border_color, pad_x, pad_y,
highlight_color, line_thickness)
def framed(self, border_width, border_color, pad_x, pad_y, highlight_color=None):
return TextFrame(self, border_width, border_color, pad_x, pad_y, highlight_color=highlight_color)


class TextFrame(object):
def __init__(self, layout, border_width, border_color, pad_x, pad_y,
highlight_color, line_thickness):
def __init__(self, layout, border_width, border_color, pad_x, pad_y, highlight_color=None):
self.layout = layout
self.border_width = border_width
self.border_color = border_color
self.drawer = self.layout.drawer
self.highlight_color = highlight_color
self.line_thickness = line_thickness

if isinstance(pad_x, collections.Iterable):
self.pad_left = pad_x[0]
Expand All @@ -159,8 +155,7 @@ def __init__(self, layout, border_width, border_color, pad_x, pad_y,
else:
self.pad_top = self.pad_bottom = pad_y

def draw(self, x, y, bar_height=None, rounded=True, fill=False,
line=False):
def draw(self, x, y, rounded=True, fill=False, line=False, highlight=False):
self.drawer.set_source_rgb(self.border_color)
opts = [
x, y,
Expand All @@ -169,27 +164,16 @@ def draw(self, x, y, bar_height=None, rounded=True, fill=False,
self.border_width
]
if line:
if not bar_height:
bar_height = self.layout.height + self.pad_top + self.pad_bottom
highlight_opts = [
x, 0,
self.layout.width + self.pad_left + self.pad_right,
bar_height,
self.border_width
]
self.drawer.set_source_rgb(self.highlight_color)
self.drawer.fillrect(*highlight_opts)

lineopts = [
x,
bar_height - self.line_thickness,
self.layout.width + self.pad_left + self.pad_right,
self.line_thickness,
self.border_width
]
if highlight:
self.drawer.set_source_rgb(self.highlight_color)
self.drawer.fillrect(*opts)
self.drawer.set_source_rgb(self.border_color)

# change to only fill in bottom line
opts[1] = self.height - self.border_width # y
opts[3] = self.border_width # height

self.drawer.set_source_rgb(self.border_color)
self.drawer.fillrect(*lineopts)
self.drawer.fillrect(*opts)
elif fill:
if rounded:
self.drawer.rounded_fillrect(*opts)
Expand All @@ -207,10 +191,10 @@ def draw(self, x, y, bar_height=None, rounded=True, fill=False,
)

def draw_fill(self, x, y, rounded=True):
self.draw(x, y, rounded, fill=True)
self.draw(x, y, rounded=rounded, fill=True)

def draw_line(self, x, y, bar_height, rounded=False):
self.draw(x, y, bar_height, rounded, line=True)
def draw_line(self, x, y, highlighted):
self.draw(x, y, line=True, highlight=highlighted)

@property
def height(self):
Expand Down
79 changes: 35 additions & 44 deletions libqtile/widget/groupbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,24 @@ def hook_response(*args, **kwargs):
hook.subscribe.current_screen_change(hook_response)
hook.subscribe.changegroup(hook_response)

def drawbox(self, offset, text, bordercolor, textcolor, highlight_color,
line_thickness, rounded=False, block=False, width=None,
line=False):
def drawbox(self, offset, text, bordercolor, textcolor,
width=None, rounded=False, block=False, line=False, highlighted=False):
self.layout.text = text
self.layout.font_family = self.font
self.layout.font_size = self.fontsize
self.layout.colour = textcolor
if width is not None:
self.layout.width = width
if line:
pad_y = (self.bar.height - self.layout.height) / 2
else:
pad_y = self.padding_y
framed = self.layout.framed(
self.borderwidth,
bordercolor,
self.padding_x,
self.padding_y,
highlight_color,
line_thickness
pad_y,
self.highlight_color
)
y = self.margin_y
if self.center_aligned:
Expand All @@ -111,7 +113,7 @@ def drawbox(self, offset, text, bordercolor, textcolor, highlight_color,
if block:
framed.draw_fill(offset, y, rounded)
elif line:
framed.draw_line(offset, y, self.bar.size, rounded)
framed.draw_line(offset, y, highlighted)
else:
framed.draw(offset, y, rounded)

Expand Down Expand Up @@ -151,57 +153,52 @@ class GroupBox(_GroupBase):
defaults = [
("active", "FFFFFF", "Active group font colour"),
("inactive", "404040", "Inactive group font colour"),
("urgent_text", "FF0000", "Urgent group font color"),
(
"highlight_method",
"border",
"Method of highlighting ('border', 'block', 'text', or 'line')"
"Uses \*_border color settings"
),
("rounded", True, "To round or not to round borders"),
("rounded", True, "To round or not to round box borders"),
(
"this_current_screen_border",
"215578",
"Border colour for group on this screen when focused."
"Border or line colour for group on this screen when focused."
),
(
"this_screen_border",
"215578",
"Border or line colour for group on this screen when unfocused."
),
(
"other_screen_border",
"404040",
"Border or line colour for group on other screen."
),
(
"highlight_color",
["000000", "282828"],
"Active group highlight color when using 'line' highlight method."
),
(
"urgent_alert_method",
"border",
"Method for alerting you of WM urgent "
"hints (one of 'border', 'text', 'block', or 'line')"
),
("urgent_text", "FF0000", "Urgent group font color"),
("urgent_border", "FF0000", "Urgent border or line color"),
(
"disable_drag",
False,
"Disable dragging and dropping of group names on widget"
),
(
"this_screen_border",
"215578",
"Border colour for group on this screen."
),
(
"other_screen_border",
"404040",
"Border colour for group on other screen."
),
("urgent_border", "FF0000", "Urgent border color"),
("invert_mouse_wheel", False, "Whether to invert mouse wheel group movement"),
(
"visible_groups",
None,
"Groups that will be visible "
"(if set to None or [], all groups will be visible)"
),
(
"highlight_color",
["000000", "282828"],
"Active group highlight color when using 'line' highlight method."
),
(
"line_thickness",
2,
"Thickness of the line when using the 'line' highlight method."
)
]

Expand Down Expand Up @@ -273,10 +270,9 @@ def draw(self):

offset = 0
for i, g in enumerate(self.groups):
to_highlight = False
is_block = (self.highlight_method == 'block')
is_line = (self.highlight_method == 'line')
if not is_line:
highlight_color = None

bw = self.box_width([g])

Expand All @@ -295,36 +291,31 @@ def draw(self):
if self.bar.screen.group.name == g.name:
if self.qtile.currentScreen == self.bar.screen:
border = self.this_current_screen_border
highlight_color = self.highlight_color
to_highlight = True
else:
border = self.this_screen_border
highlight_color = self.bar.background
else:
border = self.other_screen_border
highlight_color = self.bar.background
elif self.group_has_urgent(g) and \
self.urgent_alert_method in ('border', 'block', 'line'):
border = self.urgent_border
highlight_color = self.bar.background
if self.urgent_alert_method == 'block':
is_block = True
elif self.urgent_alert_method == 'line':
is_line = True
else:
border = self.background or self.bar.background
highlight_color = self.bar.background

self.drawbox(
self.margin_x + offset,
g.name,
border,
text_color,
highlight_color,
self.line_thickness,
self.rounded,
is_block,
bw - self.margin_x * 2 - self.padding_x * 2,
is_line
width=bw - self.margin_x * 2 - self.padding_x * 2,
rounded=self.rounded,
block=is_block,
line=is_line,
highlighted=to_highlight
)
offset += bw
self.drawer.draw(offsetx=self.offset, width=self.width)
10 changes: 5 additions & 5 deletions libqtile/widget/tasklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ def drawtext(self, text, textcolor, width):
if width is not None:
self.layout.width = width

def drawbox(self, offset, text, bordercolor, textcolor, rounded=False,
block=False, width=None, icon=None):
def drawbox(self, offset, text, bordercolor, textcolor,
width=None, rounded=False, block=False, icon=None):
self.drawtext(text, textcolor, width)

icon_padding = (self.icon_size + 4) if icon else 0
Expand Down Expand Up @@ -255,9 +255,9 @@ def draw(self):
task,
border,
self.foreground,
self.rounded,
self.highlight_method == 'block',
bw - self.margin_x * 2 - self.padding_x * 2,
rounded=self.rounded,
block=(self.highlight_method == 'block'),
width=(bw - self.margin_x * 2 - self.padding_x * 2),
icon=self.get_window_icon(w),
)

Expand Down

0 comments on commit b18fed4

Please sign in to comment.