From 6c08cae19f3eb0efac21309dabaa8b3c3150e4c5 Mon Sep 17 00:00:00 2001 From: Frantisek Bohacek Date: Sun, 24 Mar 2024 09:06:15 +0100 Subject: [PATCH] feat: recover qtile configuration, make changes for dynamic monitors --- modules/desktop/qtile/config/autostart.sh | 2 +- modules/desktop/qtile/config/config.py | 96 ++++++++++++++++++----- modules/desktop/qtile/default.nix | 20 +---- modules/desktop/qtile/home.nix | 82 ++++++++++++++----- modules/services/picom.nix | 10 +-- 5 files changed, 150 insertions(+), 60 deletions(-) diff --git a/modules/desktop/qtile/config/autostart.sh b/modules/desktop/qtile/config/autostart.sh index 640ef48..e4cc7cc 100755 --- a/modules/desktop/qtile/config/autostart.sh +++ b/modules/desktop/qtile/config/autostart.sh @@ -5,6 +5,6 @@ firefox & # Comms discord & -telegram-desktop & +element-desktop & # aw-qt & diff --git a/modules/desktop/qtile/config/config.py b/modules/desktop/qtile/config/config.py index 57424a4..c3542d9 100644 --- a/modules/desktop/qtile/config/config.py +++ b/modules/desktop/qtile/config/config.py @@ -19,6 +19,9 @@ from mpris2widget import Mpris2 from bluetooth import Bluetooth import xmonadcustom from nixenvironment import setupLocation, configLocation, sequenceDetectorExec +import time + +import screeninfo colors = { 'primary': '51afef', @@ -81,12 +84,28 @@ def go_to_group(qtile: Qtile, group_name: str, switch_monitor: bool = False): for window in current_group.windows: if window.fullscreen: window.toggle_fullscreen() + time.sleep(0.1) + window.toggle_fullscreen() if not switch_monitor or not found: window: Window for window in qtile.groups_map[group_name].windows: if window.fullscreen: window.toggle_fullscreen() + time.sleep(0.1) + window.toggle_fullscreen() + +@lazy.function +def warp_cursor_to_focused_window(qtile: Qtile): + logger.warning("warping") + current_window = qtile.current_window + win_size = current_window.get_size() + win_pos = current_window.get_position() + + x = win_pos[0] + win_size[0] // 2 + y = win_pos[1] + win_size[1] // 2 + + qtile.core.warp_pointer(x, y) # expands list of keys with the rest of regular keys, # mainly usable for KeyChords, where you want any other key @@ -345,14 +364,33 @@ def create_bottom_bar(): ), ], 30) -def init_screen(top_bar, wallpaper): - return Screen(top=top_bar, bottom=create_bottom_bar(), wallpaper=wallpaper, width=1920, height=1080) +def init_screens(): -screens = [ - init_screen(create_top_bar(), f'{setupLocation}/wall.png'), - init_screen(create_top_bar(systray = True), f'{setupLocation}/wall.png'), - init_screen(create_top_bar(), f'{setupLocation}/wall.png'), -] + wallpaper = f'{setupLocation}/wall.png' + + screens_info = screeninfo.get_monitors() + screens_count = len(screens_info) + screens = [None] * screens_count + + logger.warning(f'setting up {screens_count} screens') + + for i in range(0, screens_count): + screen_info = screens_info[i] + systray = False + if screens_count <= 2 and i == 0: + systray = True + print(f'Putting systray on {i}') + elif i == 1: + systray = True + print(f'Putting systray on {i}') + + top_bar = create_top_bar(systray = systray) + + screens[i] = Screen(top=top_bar, bottom=create_bottom_bar(), wallpaper=f'{setupLocation}/wall.png', width=screen_info.width, height=screen_info.height) + + return screens + +screens = init_screens() # Keys keys = [] @@ -374,6 +412,7 @@ keys.extend([ EzKey('M-S-m', lazy.window.toggle_minimize()), EzKey('M-t', lazy.window.disable_floating()), EzKey('M-f', lazy.window.toggle_fullscreen()), + EzKey('M-S-f', lazy.to_layout_index(1)), EzKey('M-', lazy.layout.swap_main()), EzKey('M-', lazy.next_layout()), EzKey('M-S-', lazy.to_layout_index(0), desc = 'Default layout'), @@ -393,8 +432,8 @@ keys.extend([ # social navigation EzKeyChord('M-a', expand_with_rest_keys([ EzKey('b', focus_window_by_class('discord')), - EzKey('n', focus_window_by_class('Cinny')), - EzKey('m', focus_window_by_class('Cinny')), + EzKey('n', focus_window_by_class('element')), + EzKey('m', focus_window_by_class('element')), # notifications EzKey('l', lazy.spawn(f'{setupLocation}/scripts/notifications/clear-popups.sh')), @@ -454,12 +493,18 @@ keys.extend([ ]) # Monitor navigation -monitor_navigation_keys = ['w', 'e', 'r'] +keys.extend([ + EzKey('M-C-w', warp_cursor_to_focused_window()), +]) +if len(screens) >= 4: + monitor_navigation_keys = ['q', 'w', 'e', 'r'] +else: + monitor_navigation_keys = ['w', 'e', 'r'] + for i, key in enumerate(monitor_navigation_keys): - monitor_index_map = [ 2, 0, 1 ] keys.extend([ - EzKey(f'M-{key}', lazy.to_screen(monitor_index_map[i]), desc = f'Move focus to screen {i}'), - EzKey(f'M-S-{key}', lazy.window.toscreen(monitor_index_map[i]), desc = f'Move focus to screen {i}'), + EzKey(f'M-{key}', lazy.to_screen(i), desc = f'Move focus to screen {i}'), + EzKey(f'M-S-{key}', lazy.window.toscreen(i), desc = f'Move window to screen {i}'), ]) if qtile.core.name == 'x11': @@ -510,6 +555,12 @@ groups.append( on_focus_lost_hide = True, **scratch_pad_middle ), + DropDown( + 'ipcam', + ['~/doc/utils/ip-cam.sh'], + on_focus_lost_hide = True, + **scratch_pad_middle + ), DropDown( 'bluetooth', ['blueman-manager'], @@ -611,15 +662,25 @@ def startup_applications(client: Window): if client.match(Match(wm_class = 'firefox')) and firefoxInstance <= 1: client.togroup(groups[firefoxInstance].name) firefoxInstance += 1 - elif client.match(Match(wm_class = 'discord')) or client.match(Match(wm_class = 'telegram-desktop')) or client.match(Match(wm_class = 'cinny')): + elif client.match(Match(wm_class = 'discord')) or client.match(Match(wm_class = 'telegram-desktop')) or client.match(Match(wm_class = 'element')): client.togroup(groups[8].name) @hook.subscribe.screen_change @lazy.function def set_screens(qtile, event): - if not os.path.exists(os.path.expanduser('~/NO-AUTORANDR')): - subprocess.run(["autorandr", "--change"]) - qtile.cmd_restart() + logger.warning("screen change") + logger.warning(event) + # if not os.path.exists(os.path.expanduser('~/NO-AUTORANDR')): + # subprocess.run(["autorandr", "--change"]) + # qtile.cmd_restart() + +@hook.subscribe.screens_reconfigured +@lazy.function +def screen_reconf(qtile): + logger.warning("screens reconfigured") + l = len(screens) + l2 = len(qtile.screens) + logger.warnings(f"Reconfigured screens, length of our screens: {l}, of qtile's screens: {l2}") # Turn off fullscreen on unfocus @hook.subscribe.client_focus @@ -653,4 +714,3 @@ def scratchpad_startup(): return hide_dropdown hook.subscribe.client_managed(wrapper(dropdown_name)) - diff --git a/modules/desktop/qtile/default.nix b/modules/desktop/qtile/default.nix index 8025a87..6a4fcaf 100644 --- a/modules/desktop/qtile/default.nix +++ b/modules/desktop/qtile/default.nix @@ -5,24 +5,6 @@ xkblayout-state ]; - nixpkgs.overlays = [ - (final: super: { - pythonPackagesOverlays = (super.pythonPackagesOverlays or []) ++ [ - (_: pprev: { - qtile-extras = pprev.qtile-extras.overridePythonAttrs(_: { - doCheck = false; - }); - }) - ]; - - python3 = let self = super.python3.override { - inherit self; - packageOverrides = super.lib.composeManyExtensions final.pythonPackagesOverlays; - }; in self; - python3Packages = final.python3.pkgs; - }) - ]; - services = { xserver = { enable = true; @@ -30,6 +12,8 @@ enable = true; extraPackages = ppkgs: [ ppkgs.qtile-extras + ppkgs.xlib + ppkgs.screeninfo ]; }; }; diff --git a/modules/desktop/qtile/home.nix b/modules/desktop/qtile/home.nix index 2594941..4b45d0a 100644 --- a/modules/desktop/qtile/home.nix +++ b/modules/desktop/qtile/home.nix @@ -1,6 +1,6 @@ { config, lib, pkgs, user, location, ... }: -let +let nur = config.nur.repos; in { # services.udev.extraRules = @@ -34,18 +34,18 @@ in { enable = true; hooks = { postswitch = { - "reload-qtile" = "${pkgs.qtile}/bin/qtile cmd-obj -o cmd -f reload_config"; + # "reload-qtile" = "${pkgs.qtile}/bin/qtile cmd-obj -o cmd -f reload_config"; }; }; profiles = { - "desktop" = { + "home-docked" = { fingerprint = { - DVI-D-0 = "00ffffffffffff0009d1d978455400002b1a010380351e782e6c40a755519f27145054a56b80d1c081c081008180a9c0b30001010101023a801871382d40582c45000f282100001e000000ff0054414730333931303031390a20000000fd00324c1e5311000a202020202020000000fc0042656e51204757323437300a200161020322f14f901f05140413031207161501061102230907078301000065030c002000023a801871382d40582c45000f282100001e011d8018711c1620582c25000f282100009e011d007251d01e206e2855000f282100001e8c0ad08a20e02d10103e96000f2821000018000000000000000000000000000000000000000000f5"; - DisplayPort-0 = "00ffffffffffff0009d1e77801010101261e0104a5351e783a05f5a557529c270b5054a56b80d1c0b300a9c08180810081c001010101023a801871382d40582c45000f282100001e000000ff00455442394c3033373432534c30000000fd00324c1e5311010a202020202020000000fc0042656e51204757323438300a2001e002031cf14f901f041303120211011406071516052309070783010000023a801871382d40582c45000f282100001f011d8018711c1620582c25000f282100009f011d007251d01e206e2855000f282100001e8c0ad08a20e02d10103e96000f28210000180000000000000000000000000000000000000000000000000000008d"; - HDMI-A-0 = "00ffffffffffff0009d1e778455400000d1c010380351e782e0565a756529c270f5054a56b80d1c0b300a9c08180810081c001010101023a801871382d40582c45000f282100001e000000ff0058334a30303131303031510a20000000fd00324c1e5311000a202020202020000000fc0042656e51204757323438300a2001b0020322f14f901f04130312021101140607151605230907078301000065030c001000023a801871382d40582c45000f282100001f011d8018711c1620582c25000f282100009f011d007251d01e206e2855000f282100001e8c0ad08a20e02d10103e96000f282100001800000000000000000000000000000000000000000003"; + "DP-7" = "00ffffffffffff0009d1e77801010101261e0104a5351e783a05f5a557529c270b5054a56b80d1c0b300a9c08180810081c001010101023a801871382d40582c45000f282100001e000000ff00455442394c3033373432534c30000000fd00324c1e5311010a202020202020000000fc0042656e51204757323438300a2001e002031cf14f901f041303120211011406071516052309070783010000023a801871382d40582c45000f282100001f011d8018711c1620582c25000f282100009f011d007251d01e206e2855000f282100001e8c0ad08a20e02d10103e96000f28210000180000000000000000000000000000000000000000000000000000008d"; + "DP-8" = "00ffffffffffff0009d1e778455400000d1c0104a5351e783a0565a756529c270f5054a56b80d1c0b300a9c08180810081c001010101023a801871382d40582c45000f282100001e000000ff0058334a30303131303031510a20000000fd00324c1e5311010a202020202020000000fc0042656e51204757323438300a20017d02031cf14f901f041303120211011406071516052309070783010000023a801871382d40582c45000f282100001f011d8018711c1620582c25000f282100009f011d007251d01e206e2855000f282100001e8c0ad08a20e02d10103e96000f28210000180000000000000000000000000000000000000000000000000000008d"; + "DP-9" = "00ffffffffffff0009d1d978455400002b1a010380351e782e6c40a755519f27145054a56b80d1c081c081008180a9c0b30001010101023a801871382d40582c45000f282100001e000000ff0054414730333931303031390a20000000fd00324c1e5311000a202020202020000000fc0042656e51204757323437300a200161020322f14f901f05140413031207161501061102230907078301000065030c001000023a801871382d40582c45000f282100001e011d8018711c1620582c25000f282100009e011d007251d01e206e2855000f282100001e8c0ad08a20e02d10103e96000f282100001800000000000000000000000000000000000000000005"; }; config = { - DVI-D-0 = { + DP-9 = { enable = true; crtc = 0; primary = false; @@ -54,7 +54,7 @@ in { gamma = "1.0:0.909:0.833"; rate = "60.00"; }; - DisplayPort-0 = { + DP-7 = { enable = true; crtc = 0; primary = true; @@ -63,34 +63,80 @@ in { gamma = "1.0:0.909:0.833"; rate = "60.00"; }; - HDMI-A-0 = { + DP-8 = { enable = true; crtc = 0; - primary = true; + primary = false; position = "3840x0"; mode = "1920x1080"; gamma = "1.0:0.909:0.833"; rate = "60.00"; }; + eDP-1 = { + enable = false; + }; }; }; - "virtual" = { + "home-internal" = { fingerprint = { - Virtual-1 = "00ffffffffffff0049143412000000002a180104a530197806ee91a3544c99260f5054210800e1c0d1c0d100a940b3009500818081405a4f80a072f22330e0395540e70011000018000000f7000a004082002820000000000000000000fd00327d1ea0ff010a202020202020000000fc0051454d55204d6f6e69746f720a019902030b00467d6560591f6100000010000000000000000000000000000000000010000000000000000000000000000000000010000000000000000000000000000000000010000000000000000000000000000000000010000000000000000000000000000000000010000000000000000000000000000000000000000000002f"; - Virtual-2 = "00ffffffffffff0049143412000000002a180104a5301b7806ee91a3544c99260f5054210800e1c0d1c0d100a940b300950081808140d25480a072382540e0395540e71211000018000000f7000a004082002820000000000000000000fd00327d1ea0ff010a202020202020000000fc0051454d55204d6f6e69746f720a01b002030b00467d6560591f6100000010000000000000000000000000000000000010000000000000000000000000000000000010000000000000000000000000000000000010000000000000000000000000000000000010000000000000000000000000000000000010000000000000000000000000000000000000000000002f"; + "DP-7" = "00ffffffffffff0009d1e77801010101261e0104a5351e783a05f5a557529c270b5054a56b80d1c0b300a9c08180810081c001010101023a801871382d40582c45000f282100001e000000ff00455442394c3033373432534c30000000fd00324c1e5311010a202020202020000000fc0042656e51204757323438300a2001e002031cf14f901f041303120211011406071516052309070783010000023a801871382d40582c45000f282100001f011d8018711c1620582c25000f282100009f011d007251d01e206e2855000f282100001e8c0ad08a20e02d10103e96000f28210000180000000000000000000000000000000000000000000000000000008d"; + "DP-8" = "00ffffffffffff0009d1e778455400000d1c0104a5351e783a0565a756529c270f5054a56b80d1c0b300a9c08180810081c001010101023a801871382d40582c45000f282100001e000000ff0058334a30303131303031510a20000000fd00324c1e5311010a202020202020000000fc0042656e51204757323438300a20017d02031cf14f901f041303120211011406071516052309070783010000023a801871382d40582c45000f282100001f011d8018711c1620582c25000f282100009f011d007251d01e206e2855000f282100001e8c0ad08a20e02d10103e96000f28210000180000000000000000000000000000000000000000000000000000008d"; + "DP-9" = "00ffffffffffff0009d1d978455400002b1a010380351e782e6c40a755519f27145054a56b80d1c081c081008180a9c0b30001010101023a801871382d40582c45000f282100001e000000ff0054414730333931303031390a20000000fd00324c1e5311000a202020202020000000fc0042656e51204757323437300a200161020322f14f901f05140413031207161501061102230907078301000065030c001000023a801871382d40582c45000f282100001e011d8018711c1620582c25000f282100009e011d007251d01e206e2855000f282100001e8c0ad08a20e02d10103e96000f282100001800000000000000000000000000000000000000000005"; + "eDP-1" = "00ffffffffffff0009e5660b000000001a200104a51e137807e957a7544c9a26115457000000010101010101010101010101010101019c3e80c870b03c40302036002ebc1000001a163280c870b03c40302036002ebc1000001a000000fd001e3c4c4c10010a202020202020000000fe004e4531343057554d2d4e36470a00f7"; }; + config = { - Virtual-1 = { + DP-9 = { enable = true; - primary = true; + crtc = 0; + primary = false; position = "0x0"; mode = "1920x1080"; + gamma = "1.0:0.909:0.833"; + rate = "60.00"; }; - Virtual-2 = { - enable = true; - primary = false; + DP-7 = { + enable = false; + crtc = 0; + primary = true; position = "1920x0"; mode = "1920x1080"; + gamma = "1.0:0.909:0.833"; + rate = "60.00"; + }; + DP-8 = { + enable = false; + crtc = 0; + primary = false; + position = "3840x0"; + mode = "1920x1080"; + gamma = "1.0:0.909:0.833"; + rate = "60.00"; + }; + eDP-1 = { + enable = true; + crtc = 0; + primary = true; + position = "1920x1080"; + mode = "1920x1200"; + gamma = "1.0:0.909:0.833"; + rate = "60.00"; + }; + }; + }; + "notebook" = { + fingerprint = { + "eDP-1" = "00ffffffffffff0009e5660b000000001a200104a51e137807e957a7544c9a26115457000000010101010101010101010101010101019c3e80c870b03c40302036002ebc1000001a163280c870b03c40302036002ebc1000001a000000fd001e3c4c4c10010a202020202020000000fe004e4531343057554d2d4e36470a00f7"; + }; + config = { + eDP-1 = { + enable = true; + crtc = 0; + primary = true; + position = "0x0"; + mode = "1920x1200"; + gamma = "1.0:0.909:0.833"; + rate = "60.00"; }; }; }; diff --git a/modules/services/picom.nix b/modules/services/picom.nix index 49ea4ab..9647d4c 100644 --- a/modules/services/picom.nix +++ b/modules/services/picom.nix @@ -6,7 +6,7 @@ { services.picom = { - # enable = true; + enable = true; package = pkgs.picom; backend = "glx"; # Rendering either with glx or xrender. You'll know if you need to switch this. @@ -24,10 +24,10 @@ # "100:name = 'Picture in picture'" # "100:name = 'Picture-in-Picture'" # "85:class_i ?= 'rofi'" - "90:class_i *= 'discord'" - "90:class_i *= 'telegram-desktop'" - "90:class_i *= 'emacs'" - "90:class_i *= 'Alacritty'" + # "90:class_i *= 'discord'" + # "90:class_i *= 'telegram-desktop'" + # "90:class_i *= 'emacs'" + # "90:class_i *= 'Alacritty'" # "100:fullscreen" ]; # Find with $ xprop | grep "WM_CLASS" -- 2.48.1