From 3f7d6c9821a957fe47958b6e22edc0ec41a53a84 Mon Sep 17 00:00:00 2001 From: Jeena Date: Sat, 30 Aug 2025 10:33:19 +0900 Subject: [PATCH] Add shortcut cheatsheet --- hypr/keybindings.conf | 4 ++ hypr/menu.list | 2 +- hypr/scripts/cheatsheet.py | 81 ++++++++++++++++++++++++++++++++++++++ hypr/shortcuts.txt | 21 ++++++++++ hypr/windowrule.conf | 6 +++ 5 files changed, 113 insertions(+), 1 deletion(-) create mode 100755 hypr/scripts/cheatsheet.py create mode 100644 hypr/shortcuts.txt diff --git a/hypr/keybindings.conf b/hypr/keybindings.conf index b31fb58..e7cf4a3 100644 --- a/hypr/keybindings.conf +++ b/hypr/keybindings.conf @@ -18,3 +18,7 @@ bind = shift, PRINT, exec, hyprshot -m region # Lock bind = $mainMod, L, exec, ~/.config/hypr/scripts/lock.sh bind = $mainMod SHIFT, L, exec, wlogout --protocol layer-shell + +# Cheatsheet +bind = $mainMod, F1, exec, ~/.config/hypr/scripts/cheatsheet.py ~/.config/hypr/shortcuts.txt + diff --git a/hypr/menu.list b/hypr/menu.list index aa95435..6008e99 100644 --- a/hypr/menu.list +++ b/hypr/menu.list @@ -1,2 +1,2 @@ Emoji Picker=emoji-picker.py - +Shortcuts=cheatsheet.py ~/.config/hypr/shortcuts.txt diff --git a/hypr/scripts/cheatsheet.py b/hypr/scripts/cheatsheet.py new file mode 100755 index 0000000..243b7d3 --- /dev/null +++ b/hypr/scripts/cheatsheet.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 + +import gi, sys +gi.require_version("Gtk", "4.0") +gi.require_version("Adw", "1") +from gi.repository import Gtk, Adw, Gdk, Pango, Gio + +class Cheatsheet(Adw.Application): + def __init__(self, path): + super().__init__(application_id="net.jeena.Cheatsheet") + self.path = path + + def do_activate(self): + win = self.create_window() + container, label = self.create_cheatsheet_label(self.path) + self.apply_css(container, label) + win.set_content(container) + win.present() + + def create_window(self): + win = Adw.ApplicationWindow(application=self) + win.set_title("Hyprland Cheatsheet") + win.set_default_size(980, 400) + win.set_resizable(True) + win.set_decorated(False) + win.set_opacity(0.7) + win.add_css_class("cheatsheet") + + key_controller = Gtk.EventControllerKey() + key_controller.connect("key-pressed", self.on_key) + win.add_controller(key_controller) + return win + + def create_cheatsheet_label(self, filepath): + container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) + container.set_margin_top(10) + container.set_margin_bottom(10) + container.set_margin_start(10) + container.set_margin_end(10) + + label = Gtk.Label() + label.set_xalign(0) + label.set_yalign(0) + label.set_wrap(True) + label.set_justify(Gtk.Justification.LEFT) + label.set_text(open(filepath).read().rstrip('\n')) + label.set_selectable(False) + + container.append(label) + return container, label + + def apply_css(self, container, label): + css_provider = Gtk.CssProvider() + css_provider.load_from_data(b""" + window.cheatsheet { + background-color: rgba(0,0,0,0.7); + border-radius: 10px; + } + + window.cheatsheet label { + font-family: "JetBrains Mono Nerd Font"; + font-size: 12pt; + font-weight: bold; + color: #ffffff; + } + """) + Gtk.StyleContext.add_provider_for_display( + Gdk.Display.get_default(), + css_provider, + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION + ) + + def on_key(self, controller, keyval, keycode, state): + key_name = Gdk.keyval_name(keyval) + if key_name == "Escape": + self.get_active_window().close() + return True + +if __name__ == "__main__": + app = Cheatsheet(sys.argv[1]) + app.run() diff --git a/hypr/shortcuts.txt b/hypr/shortcuts.txt new file mode 100644 index 0000000..464b7f5 --- /dev/null +++ b/hypr/shortcuts.txt @@ -0,0 +1,21 @@ +┌────────────────── Applications ────────────────────┐ ┌───────────── Window Management ───────────┐ +│ SUPER + T Open terminal │ │ SUPER + W Close focused window │ +│ SUPER + B Open browser │ │ SUPER + M Exit Hyprland │ +│ SUPER + E Open file manager │ │ SUPER + V Toggle floating │ +└────────────────────────────────────────────────────┘ │ SUPER + P Pseudo split (dwindle) │ +┌───────────────── Focus Movement ───────────────────┐ │ SUPER + J Toggle split (dwindle) │ +│ SUPER + ←/→/↑/↓ Move focus │ │ SUPER + F Toggle fullscreen │ +└────────────────────────────────────────────────────┘ └───────────────────────────────────────────┘ +┌─────────────────── Workspace ──────────────────────┐ ┌────────────────── Menu ───────────────────┐ +│ SUPER + [1–9,0] Switch to workspace 1–10 │ │ Tap SUPER App menu tofi │ +│ SUPER + SHIFT + [1–9,0] Move window to workspace │ └───────────────────────────────────────────┘ +│ SUPER + S Toggle special workspace │ ┌─────────────── Screenshot ────────────────┐ +│ SUPER + SHIFT + S Move to special workspace │ │ Print Screenshot window │ +│ SUPER + Mouse wheel Switch workspaces │ │ Shift + Print Screenshot region │ +│ CTRL + ALT + ←/→ Previous / Next workspace │ └───────────────────────────────────────────┘ +└────────────────────────────────────────────────────┘ ┌────────────── Lock / Logout ──────────────┐ +┌──────────── Window Moving/Resizing ────────────────┐ │ SUPER + L Lock screen │ +│ SUPER + LMB (drag) Move window │ │ SUPER + SHIFT + L Logout menu │ +│ SUPER + RMB (drag) Resize window │ └───────────────────────────────────────────┘ +│ SUPER + SHIFT + ←/→/↑/↓ Swap window with neighbor │ +└────────────────────────────────────────────────────┘ diff --git a/hypr/windowrule.conf b/hypr/windowrule.conf index 0c2a966..7343682 100644 --- a/hypr/windowrule.conf +++ b/hypr/windowrule.conf @@ -1,3 +1,9 @@ # Librewolf Picture-in-Picture windowrulev2 = float, class:($browser),title:(Picture-in-Picture) windowrulev2 = pin, class:($browser),title:(Picture-in-Picture) + +# Cheatsheet +windowrulev2 = float, class:net.jeena.Cheatsheet +windowrulev2 = center, class:net.jeena.Cheatsheet +windowrulev2 = stayfocused, class:net.jeena.Cheatsheet +