Skip to content

Commit

Permalink
changed dotfiles to work on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
gerblesh committed Aug 19, 2023
1 parent ac58eec commit 435ecca
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 18 deletions.
139 changes: 139 additions & 0 deletions usr/bin/sway-autoname-workspaces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/usr/bin/python3

# This script requires i3ipc-python package (install it from a system package manager
# or pip).
# It adds icons to the workspace name for each open window.
# Set your keybindings like this: set $workspace1 workspace number 1
# Add your icons to WINDOW_ICONS.
# Based on https://github.com/maximbaz/dotfiles/blob/master/bin/i3-autoname-workspaces

import argparse
import i3ipc
import logging
import re
import signal
import sys

WINDOW_ICONS = {
"firefox": "",
"godot": "",
"foot": "",
"brave-browser": "",
"lite-xl": "",
"spot": "",
"com.github.neithern.g4music": "󰝚",
"thunar": "󰪶",
"mpv": "󰈫",
"imv": "",
"com.obsproject.Studio": "󰑋",
"obsidian": "󱓧"
}

DEFAULT_ICON = ""


def icon_for_window(window):
name = None
if window.app_id is not None and len(window.app_id) > 0:
name = window.app_id.lower()
elif window.window_class is not None and len(window.window_class) > 0:
name = window.window_class.lower()


if name in WINDOW_ICONS:
return WINDOW_ICONS[name]

logging.info("No icon available for window with name: %s" % str(name))
return DEFAULT_ICON

def rename_workspaces(ipc):
for workspace in ipc.get_tree().workspaces():
name_parts = parse_workspace_name(workspace.name)
icon_tuple = ()
for w in workspace:
if w.app_id is not None or w.window_class is not None:
icon = icon_for_window(w)
if not ARGUMENTS.duplicates and icon in icon_tuple:
continue
icon_tuple += (icon,)
name_parts["icons"] = " ".join(icon_tuple) + " "

new_name = construct_workspace_name(name_parts)
ipc.command('rename workspace "%s" to "%s"' % (workspace.name, str(new_name)))


def undo_window_renaming(ipc):
for workspace in ipc.get_tree().workspaces():
name_parts = parse_workspace_name(workspace.name)
name_parts["icons"] = None
new_name = construct_workspace_name(name_parts)
ipc.command('rename workspace "%s" to "%s"' % (workspace.name, new_name))
ipc.main_quit()
sys.exit(0)


def parse_workspace_name(name):
return re.match(
"(?P<num>[0-9]+):?(?P<shortname>\w+)? ?(?P<icons>.+)?", name
).groupdict()


def construct_workspace_name(parts):
new_name = parts["num"]
icons = parts["icons"]
if icons:
icons = icons.replace(" ", "")

if parts["shortname"] or icons:
new_name += ":"

if parts["shortname"]:
new_name += parts["shortname"]

if parts["icons"]:
new_name += " " + parts["icons"]
return new_name


if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="This script automatically changes the workspace name in sway depending on your open applications."
)
parser.add_argument(
"--duplicates",
"-d",
action="store_true",
help="Set it when you want an icon for each instance of the same application per workspace.",
)
parser.add_argument(
"--logfile",
"-l",
type=str,
default="/tmp/sway-autoname-workspaces.log",
help="Path for the logfile.",
)
args = parser.parse_args()
global ARGUMENTS
ARGUMENTS = args

logging.basicConfig(
level=logging.INFO,
filename=ARGUMENTS.logfile,
filemode="w",
format="%(message)s",
)

ipc = i3ipc.Connection()

for sig in [signal.SIGINT, signal.SIGTERM]:
signal.signal(sig, lambda signal, frame: undo_window_renaming(ipc))

def window_event_handler(ipc, e):
if e.change in ["new", "close", "move"]:
rename_workspaces(ipc)

ipc.on("window", window_event_handler)

rename_workspaces(ipc)

ipc.main()
6 changes: 4 additions & 2 deletions usr/bin/wallpaper
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

WALLPAPER_PATH=""
# Default Wallpaper, feel free to change this to whatever you like
DEFAULT_WALLPAPER="$HOME/Pictures/Wallpapers/Mocha/fedora.jpg"
DEFAULT_WALLPAPER="$HOME/Pictures/Wallpapers/Mocha/mocha-background.jpg"

if [ ! -f "$HOME/.config/wallpaper" ]; then
echo "$DEFAULT_WALLPAPER" > "$HOME/.config/wallpaper"
Expand All @@ -21,5 +21,7 @@ else
WALLPAPER_PATH="$1"
fi

swaybg -i "$WALLPAPER_PATH" -m fill &
FULL_WALLPAPER_PATH="${WALLPAPER_PATH/#\~/$HOME}"

swaybg -i "$FULL_WALLPAPER_PATH" -m fill &

2 changes: 2 additions & 0 deletions usr/etc/homedir/.config/sway/config.d/execs.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
exec blueman-applet
exec nm-applet
exec wl-paste --watch cliphist store
exec /usr/bin/sway-autoname-workspaces.py


exec swayidle -w \
timeout 300 '/usr/bin/lock.sh' \
Expand Down
1 change: 1 addition & 0 deletions usr/etc/homedir/.config/wallpaper
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
~/Pictures/Wallpapers/Mocha/mocha-background.jpg
14 changes: 1 addition & 13 deletions usr/etc/homedir/.config/waybar/config
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,9 @@
},

"sway/workspaces": {
"on-scroll-up": "hyprctl dispatch workspace e+1",
"on-scroll-down": "hyprctl dispatch workspace e-1",
"all-outputs": true,
"on-click": "activate",
"format": "{name}",
"format-icons": {
"1": "",
"2": "",
"3": "",
"4": "",
"5": "",
"urgent": "",
"active": "",
"default": ""
}
"format": "{value}",
},

"pulseaudio": {
Expand Down
6 changes: 3 additions & 3 deletions usr/etc/homedir/.config/waybar/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@
min-height: 0;
margin: 0;
padding: 0;
font-weight: 600;
}

/* The whole bar */
#waybar {
color: @text;
font-family: OverpassMono Nerd Font;
font-family: Cantarell, Overpass Nerd Font;
font-size: 20px;
border-bottom: 2px solid @shadow;
background-color: @main;
Expand Down Expand Up @@ -110,7 +111,6 @@
}

#clock {
font-weight: bold;
color: @tertiary;
}

Expand Down Expand Up @@ -188,7 +188,7 @@
}

#window {
font-weight: bold;
/*no styles*/
}
#idle_inhibitor.activated,
#mode,
Expand Down
File renamed without changes
File renamed without changes

0 comments on commit 435ecca

Please sign in to comment.