-
-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sway workspaces #191
base: master
Are you sure you want to change the base?
Sway workspaces #191
Changes from 1 commit
05bac01
ee8271c
0f20063
e3fc32a
de94b6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,11 @@ | |
|
||
|
||
class SwayWorkspaces(Gtk.Box): | ||
def __init__(self, settings, i3, icons_path): | ||
def __init__(self, settings, i3, icons_path, output): | ||
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL, spacing=0) | ||
self.settings = settings | ||
self.i3 = i3 | ||
self.panel_output = output | ||
self.num_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) | ||
self.ws_num2box = {} | ||
self.ws_num2lbl = {} | ||
|
@@ -34,6 +35,7 @@ def build_box(self): | |
check_key(self.settings, "mark-autotiling", True) | ||
check_key(self.settings, "mark-content", True) | ||
check_key(self.settings, "hide-empty", False) | ||
check_key(self.settings, "hide-other-outputs", False) | ||
check_key(self.settings, "show-layout", True) | ||
check_key(self.settings, "angle", 0.0) | ||
if self.settings["angle"] != 0.0: | ||
|
@@ -42,27 +44,17 @@ def build_box(self): | |
# prevent from #142 | ||
ws_num = -1 | ||
if self.i3.get_tree().find_focused(): | ||
ws_num, win_name, win_id, non_empty, win_layout, numbers = self.find_details() | ||
|
||
if len(self.settings["custom-labels"]) == 1 or len(self.settings["custom-labels"]) == len(self.settings["numbers"]): | ||
self.settings["custom-labels"] *= len(self.settings["numbers"]) | ||
else: | ||
self.settings["custom-labels"] = [] | ||
|
||
if len(self.settings["focused-labels"]) == 1 or len(self.settings["focused-labels"]) == len(self.settings["numbers"]): | ||
self.settings["focused-labels"] *= len(self.settings["numbers"]) | ||
else: | ||
self.settings["focused-labels"] = [] | ||
ws_num, win_name, win_id, non_empty, win_layout, numbers, ws_defs = self.find_details() | ||
|
||
self.pack_start(self.num_box, False, False, 0) | ||
|
||
for idx, num in enumerate(self.settings["numbers"]): | ||
if num == str(ws_num) and self.settings["focused-labels"]: | ||
label = self.settings["focused-labels"][idx] | ||
elif self.settings["custom-labels"]: | ||
label = self.settings["custom-labels"][idx] | ||
else: | ||
label = str(num) | ||
try: | ||
int_num = int(num) | ||
except: | ||
int_num = 0 | ||
|
||
label = self.get_ws_label(int_num, focused = (str(num) == str(ws_num))) | ||
|
||
eb, lbl = self.build_number(num, label) | ||
self.num_box.pack_start(eb, False, False, 0) | ||
|
@@ -114,9 +106,47 @@ def build_number(self, num, label): | |
|
||
return eb, lbl | ||
|
||
def get_ws_label(self, num, idx = None, ws_defs = None, focused = False): | ||
""" | ||
Get the text to display for a workspace: | ||
- num: the number of the workspace (as integer) | ||
- idx: the index of the workspace in ws_defs (if defined) | ||
- focused: if the workspace is currently focused | ||
- ws_defs: as returned by find_details() | ||
""" | ||
|
||
# config_idx is the index of the current workspace in the | ||
# configuration. It is the index of the workspace in the | ||
# numbers config field, or the an index based on the | ||
# workspace number, first workspace being number 1 | ||
config_idx = None | ||
if num in self.settings["numbers"]: | ||
config_idx = self.settings["numbers"].index(num) | ||
elif len(self.settings["numbers"]) == 0: | ||
config_idx = num - 1 | ||
|
||
if focused: | ||
labels = self.settings["focused-labels"] | ||
else: | ||
labels = self.settings["custom-labels"] | ||
Comment on lines
+128
to
+131
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. previously it fallbacks to custom-labels if focused-labels not defined, need to implement this as well. |
||
|
||
if labels and config_idx in range(len(labels)): | ||
text = labels[config_idx] | ||
elif labels and len(labels) == 1: | ||
text = labels[0] | ||
elif idx in range(len(ws_defs)): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. default value of |
||
text = ws_defs[idx]['name'] | ||
else: | ||
text = str(num) | ||
|
||
return text | ||
|
||
def refresh(self): | ||
if self.i3.get_tree().find_focused(): | ||
ws_num, win_name, win_id, non_empty, win_layout, numbers = self.find_details() | ||
ws_num, win_name, win_id, non_empty, win_layout, numbers, ws_defs = self.find_details() | ||
|
||
custom_labels = self.settings["custom-labels"] | ||
focused_labels = self.settings["focused-labels"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not accessed |
||
|
||
if len(self.settings["numbers"]) > 0: | ||
numbers = self.settings["numbers"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if numbers is set in config, it's not guaranteed to match ws_defs |
||
|
@@ -125,23 +155,15 @@ def refresh(self): | |
for num in self.ws_num2lbl: | ||
self.ws_num2lbl[num].hide() | ||
|
||
for _idx, num in enumerate(numbers): | ||
idx = None | ||
if num in self.settings["numbers"]: | ||
idx = self.settings["numbers"].index(num) | ||
for idx, num in enumerate(numbers): | ||
focused = (str(num) == str(ws_num)) | ||
try: | ||
int_num = int(num) | ||
except: | ||
int_num = 0 | ||
|
||
if idx is None: | ||
text = str(num) | ||
elif num == str(ws_num) and self.settings["focused-labels"]: | ||
text = self.settings["focused-labels"][idx] | ||
elif self.settings["custom-labels"]: | ||
text = self.settings["custom-labels"][idx] | ||
else: | ||
text = str(num) | ||
text = self.get_ws_label(int_num, idx, ws_defs, | ||
focused = focused) | ||
|
||
if num not in self.ws_num2lbl: | ||
eb, lbl = self.build_number(num, text) | ||
|
@@ -150,7 +172,7 @@ def refresh(self): | |
|
||
lbl = self.ws_num2lbl[num] | ||
|
||
if not self.settings["hide-empty"] or int_num in non_empty or num == str(ws_num): | ||
if not self.settings["hide-empty"] or int_num in non_empty or focused: | ||
lbl.show() | ||
else: | ||
lbl.hide() | ||
|
@@ -163,10 +185,10 @@ def refresh(self): | |
else: | ||
if text.endswith("."): | ||
text = text[0:-1] | ||
|
||
lbl.set_text(text) | ||
|
||
if num == str(ws_num): | ||
if focused: | ||
self.ws_num2box[num].set_property("name", "task-box-focused") | ||
else: | ||
self.ws_num2box[num].set_property("name", "task-box") | ||
|
@@ -229,12 +251,30 @@ def find_details(self): | |
win_id = "" # app_id if available, else window_class | ||
layout = None | ||
numbers = [] | ||
ws_defs = [] | ||
|
||
for ws in workspaces: | ||
numbers.append(str(ws.num)) | ||
_, _, name = ws.name.partition(':') | ||
if len(name) == 0: | ||
name = str(ws.num) | ||
|
||
hide_other_outputs = self.settings["hide-other-outputs"] and self.panel_output is not None | ||
if hide_other_outputs and ws.output != self.panel_output: | ||
continue | ||
|
||
ws_defs.append({ | ||
'num': int(ws.num), | ||
'name': name | ||
}) | ||
if ws.focused: | ||
ws_num = ws.num | ||
|
||
# Sort ws_defs before constructing numbers and names to ensure | ||
# dynamic workspaces always appear in sorted order | ||
ws_defs.sort(key = lambda ws: ws['num']) | ||
for _idx, ws in enumerate(ws_defs): | ||
numbers.append(ws['num']) | ||
|
||
non_empty = [] | ||
if self.settings["show-name"] or self.settings["show-icon"]: | ||
f = self.i3.get_tree().find_focused() | ||
|
@@ -273,16 +313,23 @@ def find_details(self): | |
if not layout: | ||
layout = f.parent.layout | ||
|
||
return ws_num, win_name, win_id, non_empty, layout, numbers | ||
return ws_num, win_name, win_id, non_empty, layout, numbers, ws_defs | ||
|
||
def on_click(self, event_box, event_button, num): | ||
nwg_panel.common.i3.command("workspace number {}".format(num)) | ||
|
||
def on_scroll(self, event_box, event): | ||
hide_other_outputs = self.settings["hide-other-outputs"] and self.panel_output is not None | ||
if event.direction == Gdk.ScrollDirection.UP: | ||
nwg_panel.common.i3.command("workspace prev") | ||
if hide_other_outputs: | ||
nwg_panel.common.i3.command("workspace prev_on_output") | ||
else: | ||
nwg_panel.common.i3.command("workspace prev") | ||
elif event.direction == Gdk.ScrollDirection.DOWN: | ||
nwg_panel.common.i3.command("workspace next") | ||
if hide_other_outputs: | ||
nwg_panel.common.i3.command("workspace next_on_output") | ||
else: | ||
nwg_panel.common.i3.command("workspace next") | ||
|
||
def on_enter_notify_event(self, widget, event): | ||
widget.set_state_flags(Gtk.StateFlags.DROP_ACTIVE, clear=False) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
settings["numbers"]
is stored as a list of str, int-based lookup fails here