Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
[+] new/empty workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
CarloCattano committed Feb 29, 2024
1 parent 1a1c1e4 commit 34c0954
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ Simply bind the `workspaced.py` script to a key or integrate it into your system

- **Move Window to Workspace**: hold shift while clicking on a workspace, and the last active window will be moved to the selected workspace.

### Features

- One screenshot per ws/monitor
- Customizable colors
- Move last focused window to workspace (holding left shift while clicking on a workspace)
- New Empty workspace [ + ] to go or move a window to a new workspace (while holding shift)

#### Example Keybinding

```bash
Expand Down Expand Up @@ -74,6 +81,7 @@ Example configuration for Waybar, trigger the Workspace Switcher when clicking o

- Implement navigation with vim keys (hjkl)
- Test compatibility with animations
- ~~Draw an empty workspace extra to move a window to a new workspace~~
- ~~Prevent script from executing multiple instances~~
- ~~Automatically remove empty workspaces when windows are closed~~
- ~~Optimize screenshot mechanism for faster performance~~
Expand Down
19 changes: 19 additions & 0 deletions workspaced.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,19 @@ def load_workspace_images(self, workspace_files):
self.grid.attach(button, column, row, 1, 1)

self.connect("key-press-event", self.on_key_press)

# new / empty workspace button - click goes to empty workspace, + shift move
# the last focused window to the new empty workspace
empty_ws_b = Gtk.Button()
plus_sign = Gtk.Label()
plus_sign.set_markup("<span font='48'>&#43;</span>")
empty_ws_b.add(plus_sign)
empty_ws_b.set_opacity(0.5)
empty_ws_b.set_size_request(image_width, image_height / 2)
empty_ws_b.set_relief(Gtk.ReliefStyle.NONE)
empty_ws_b.get_style_context().add_class("workspace-button")
empty_ws_b.connect("clicked", self.on_empty_selected)
self.grid.attach(empty_ws_b, 1, row + 1, 1, 1)

def move_last_focused_window(self, workspace_index):
last_focused_window = os.popen("hyprctl clients -j | jq '.[] | select(.focusHistoryID == 1) | .pid'").read().strip()
Expand All @@ -176,6 +189,12 @@ def on_workspace_selected(self, button, workspace_index):
os.system(f"hyprctl dispatch workspace {workspace_index + 1}")
self.destroy()

def on_empty_selected(self, button):
os.system("hyprctl dispatch workspace empty")
current_ws = int(os.popen("hyprctl activeworkspace -j | jq '.id'").read())
if self.movewindow is True:
self.move_last_focused_window(current_ws - 1)

def on_key_press(self, widget, event):
keyval = event.keyval

Expand Down

0 comments on commit 34c0954

Please sign in to comment.