cleanup WM setup
This commit is contained in:
parent
e8738e504f
commit
e9898b83cc
3 changed files with 447 additions and 398 deletions
215
modules/desktop/wm/fht-compositor/default.nix
Normal file
215
modules/desktop/wm/fht-compositor/default.nix
Normal file
|
|
@ -0,0 +1,215 @@
|
|||
{
|
||||
inputs,
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.programs.fht-compositor;
|
||||
filename = "fht-compositor.toml";
|
||||
format = pkgs.formats.toml { };
|
||||
|
||||
# (Re)starts the programs that run alongside the compositor. Run at login, and on Super+Ctrl+R
|
||||
# so they pick up rebuilt versions and config. Each runs as a systemd user unit named
|
||||
# session-<name>, which is stopped (waiting for it to exit, since single-instance apps would
|
||||
# otherwise hand off to the old one) and started again. Logs: journalctl --user -u session-<name>
|
||||
session-programs = pkgs.writeShellApplication {
|
||||
name = "session-programs";
|
||||
runtimeInputs = [ pkgs.dbus ];
|
||||
text = ''
|
||||
# Give the units this session's environment (display, desktop name, etc.)
|
||||
dbus-update-activation-environment --systemd --all
|
||||
|
||||
${lib.concatLines (
|
||||
lib.mapAttrsToList (name: command: ''
|
||||
systemctl --user stop session-${name} 2>/dev/null || true
|
||||
systemd-run --user --unit=session-${name} --collect --quiet -- sh -c ${
|
||||
lib.escapeShellArg "exec ${command}"
|
||||
}
|
||||
'') cfg.sessionPrograms
|
||||
)}
|
||||
'';
|
||||
};
|
||||
in
|
||||
{
|
||||
imports = [ inputs.fht-compositor.nixosModules.default ];
|
||||
|
||||
options.programs.fht-compositor = {
|
||||
settings = lib.mkOption {
|
||||
inherit (format) type;
|
||||
default = { };
|
||||
description = "fht-compositor's config, written to /etc/${filename}.";
|
||||
};
|
||||
|
||||
sessionPrograms = lib.mkOption {
|
||||
type = lib.types.attrsOf lib.types.str;
|
||||
default = { };
|
||||
description = "Commands started at login and restarted on Super+Ctrl+R, as systemd user units named session-<name>.";
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
# Prefer the GNOME portal (e.g. Nautilus as the file picker), falling back to GTK. This replaces
|
||||
# the portal config fht-compositor ships.
|
||||
xdg.portal.config.fht-compositor = {
|
||||
default = [
|
||||
"gnome"
|
||||
"gtk"
|
||||
];
|
||||
|
||||
# GNOME's sends them to GNOME Shell, GTK's to any notification daemon
|
||||
"org.freedesktop.impl.portal.Notification" = [ "gtk" ];
|
||||
|
||||
# GNOME's needs GNOME Shell, and GTK doesn't have one
|
||||
"org.freedesktop.impl.portal.ScreenCast" = [ "fht-compositor" ];
|
||||
};
|
||||
|
||||
environment = {
|
||||
# Called by name (rather than by store path), so Super+Ctrl+R after a rebuild runs the new version
|
||||
systemPackages = [ session-programs ];
|
||||
etc.${filename}.source = format.generate "config.toml" cfg.settings;
|
||||
};
|
||||
|
||||
programs.fht-compositor = {
|
||||
enable = true;
|
||||
package =
|
||||
inputs.fht-compositor.packages.${pkgs.stdenv.hostPlatform.system}.default.overrideAttrs
|
||||
(old: {
|
||||
patches = (old.patches or [ ]) ++ [
|
||||
./resize-tiled-windows.patch
|
||||
./lone-modifier.patch
|
||||
];
|
||||
|
||||
nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.makeWrapper ];
|
||||
|
||||
postInstall = (old.postInstall or "") + ''
|
||||
wrapProgram $out/bin/fht-compositor \
|
||||
--add-flags "-c /etc/${filename}"
|
||||
'';
|
||||
});
|
||||
|
||||
sessionPrograms.wallpaper = "${lib.getExe pkgs.swaybg} -i ${../../../../background.jpg} -m fill";
|
||||
|
||||
settings = {
|
||||
autostart = [ "session-programs" ];
|
||||
|
||||
general = {
|
||||
focus-follows-mouse = true;
|
||||
inner-gaps = 10;
|
||||
};
|
||||
|
||||
decorations = {
|
||||
border = {
|
||||
thickness = 4;
|
||||
radius = 12;
|
||||
};
|
||||
blur.disable = true;
|
||||
};
|
||||
|
||||
keybinds = {
|
||||
Alt-Tab = "focus-next-window";
|
||||
Super-q = "close-focused-window";
|
||||
Super-f = "fullscreen-focused-window";
|
||||
Super-Ctrl-q = "quit";
|
||||
Super-Ctrl-r = {
|
||||
action = "run-command";
|
||||
arg = "fht-compositor ipc action reload-config; session-programs";
|
||||
};
|
||||
|
||||
Print = {
|
||||
action = "run-command";
|
||||
arg = "${lib.getExe pkgs.grim} -g \"$(${lib.getExe pkgs.slurp})\" - | gradia";
|
||||
};
|
||||
|
||||
Super-t = {
|
||||
action = "run-command";
|
||||
arg = "ptyxis --new-window";
|
||||
};
|
||||
Super-e = {
|
||||
action = "run-command";
|
||||
arg = "nautilus";
|
||||
};
|
||||
Super-c = {
|
||||
action = "run-command";
|
||||
arg = "codium";
|
||||
};
|
||||
Super-b = {
|
||||
action = "run-command";
|
||||
arg = "librewolf";
|
||||
};
|
||||
|
||||
Super-Down = {
|
||||
action = "change-window-proportion";
|
||||
arg = 0.5;
|
||||
};
|
||||
Super-Up = {
|
||||
action = "change-window-proportion";
|
||||
arg = -0.5;
|
||||
};
|
||||
Super-Left = {
|
||||
action = "change-mwfact";
|
||||
arg = -0.1;
|
||||
};
|
||||
Super-Right = {
|
||||
action = "change-mwfact";
|
||||
arg = 0.1;
|
||||
};
|
||||
}
|
||||
// builtins.listToAttrs (
|
||||
builtins.genList (i: {
|
||||
name = "Super-${toString (i + 1)}";
|
||||
value = {
|
||||
action = "focus-workspace";
|
||||
arg = i;
|
||||
};
|
||||
}) 9
|
||||
);
|
||||
|
||||
mousebinds = {
|
||||
Super-Left = "swap-tile";
|
||||
# Works on tiled windows too (patched in, see resize-tiled-windows.patch)
|
||||
Super-Right = "resize-tile";
|
||||
Super-wheeldown = "focus-previous-workspace";
|
||||
Super-wheelup = "focus-next-workspace";
|
||||
};
|
||||
|
||||
input.touchpad = {
|
||||
natural-scrolling = true;
|
||||
click-method = "clickfinger";
|
||||
};
|
||||
|
||||
gesturebinds = {
|
||||
focus-next-workspace = {
|
||||
fingers = 3;
|
||||
direction = "left";
|
||||
min-swipe-distance = 1;
|
||||
};
|
||||
|
||||
focus-previous-workspace = {
|
||||
fingers = 3;
|
||||
direction = "right";
|
||||
min-swipe-distance = 1;
|
||||
};
|
||||
};
|
||||
|
||||
rules = [
|
||||
{
|
||||
match-app-id = [ ".*" ];
|
||||
floating = false;
|
||||
}
|
||||
];
|
||||
|
||||
outputs = {
|
||||
HDMI-A-1.position.x = 0;
|
||||
DP-3.position.x = 1920;
|
||||
};
|
||||
|
||||
cursor = {
|
||||
name = "GoogleDot-Blue";
|
||||
size = 24;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
83
modules/desktop/wm/fht-compositor/lone-modifier.patch
Normal file
83
modules/desktop/wm/fht-compositor/lone-modifier.patch
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
--- a/src/state.rs
|
||||
+++ b/src/state.rs
|
||||
@@ -724,6 +724,9 @@
|
||||
// We store both the timer and the keysym used to trigger the key action.
|
||||
// When we remove the keysym from suppressed keys we stop it.
|
||||
pub repeated_keyaction_timer: Option<(RegistrationToken, Keysym)>,
|
||||
+ // A modifier key that was pressed on its own, with no other key, button or scroll since.
|
||||
+ // Keybinds on just a modifier key (e.g. `Super_L`) run when it's released in that state.
|
||||
+ pub lone_modifier: Option<Keysym>,
|
||||
// To focus a layer-surface with an OnDemand keyboard exclusivity mode, the user must click
|
||||
// on the layer surface. Then, when we update the keyboard focus, we check against the clicked
|
||||
// layer surface
|
||||
@@ -962,6 +965,7 @@
|
||||
clock,
|
||||
suppressed_keys: HashMap::new(),
|
||||
repeated_keyaction_timer: None,
|
||||
+ lone_modifier: None,
|
||||
seat,
|
||||
devices: vec![],
|
||||
seat_state,
|
||||
--- a/src/input/mod.rs
|
||||
+++ b/src/input/mod.rs
|
||||
@@ -244,6 +244,7 @@
|
||||
})
|
||||
.map(|inhibitor| inhibitor.is_active())
|
||||
.unwrap_or(false);
|
||||
+ let mut lone_modifier_action = None;
|
||||
let action = keyboard.input(
|
||||
self,
|
||||
keycode,
|
||||
@@ -272,6 +273,20 @@
|
||||
return FilterResult::Forward;
|
||||
}
|
||||
|
||||
+ // Lone modifier taps. The key release is still forwarded to clients, and the
|
||||
+ // action is run after the input is processed.
|
||||
+ if let Some(raw) = raw {
|
||||
+ if key_state == KeyState::Pressed {
|
||||
+ state.fht.lone_modifier = raw.is_modifier_key().then_some(raw);
|
||||
+ } else if state.fht.lone_modifier.take() == Some(raw) {
|
||||
+ lone_modifier_action = find_keyaction(
|
||||
+ &state.fht.config.keybinds,
|
||||
+ &ModifiersState::default(),
|
||||
+ raw,
|
||||
+ );
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
// Handle repeating keybinds
|
||||
// FIXME: handle this properly, this breaks if there are two repeating keybinds
|
||||
if key_state == KeyState::Released {
|
||||
@@ -331,6 +346,9 @@
|
||||
if let Some((key_pattern, key_action)) = action {
|
||||
self.process_key_action(key_action, key_pattern);
|
||||
}
|
||||
+ if let Some((key_pattern, key_action)) = lone_modifier_action {
|
||||
+ self.process_key_action(key_action, key_pattern);
|
||||
+ }
|
||||
}
|
||||
|
||||
fn on_pointer_motion<B: InputBackend>(&mut self, event: B::PointerMotionEvent) {
|
||||
@@ -505,6 +523,11 @@
|
||||
let state = wl_pointer::ButtonState::from(event.state());
|
||||
let pointer = self.fht.pointer.clone();
|
||||
|
||||
+ if state == wl_pointer::ButtonState::Pressed {
|
||||
+ // e.g. Super+click shouldn't count as a lone Super tap
|
||||
+ self.fht.lone_modifier = None;
|
||||
+ }
|
||||
+
|
||||
if state == wl_pointer::ButtonState::Pressed && !pointer.is_grabbed() {
|
||||
let pointer_loc = pointer.current_location();
|
||||
let focus = self.fht.get_pointer_focus(pointer_loc);
|
||||
@@ -555,6 +578,9 @@
|
||||
}
|
||||
|
||||
fn on_pointer_axis<B: InputBackend>(&mut self, event: B::PointerAxisEvent) {
|
||||
+ // e.g. Super+scroll shouldn't count as a lone Super tap
|
||||
+ self.fht.lone_modifier = None;
|
||||
+
|
||||
let horizontal_amount_discrete = event.amount_v120(Axis::Horizontal);
|
||||
let vertical_amount_discrete = event.amount_v120(Axis::Vertical);
|
||||
let horizontal_amount = event
|
||||
191
modules/desktop/wm/fht-compositor/resize-tiled-windows.patch
Normal file
191
modules/desktop/wm/fht-compositor/resize-tiled-windows.patch
Normal file
|
|
@ -0,0 +1,191 @@
|
|||
--- a/src/space/workspace.rs
|
||||
+++ b/src/space/workspace.rs
|
||||
@@ -59,6 +59,11 @@
|
||||
window: Window,
|
||||
initial_window_geometry: Rectangle<i32, Logical>,
|
||||
edges: ResizeEdge,
|
||||
+ /// The layout values when the resize started, used when resizing a tiled window.
|
||||
+ initial_mwfact: f64,
|
||||
+ initial_proportion: f64,
|
||||
+ /// The sum of the proportions of the other tiles in the window's stack.
|
||||
+ initial_peers_proportion: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -2009,23 +2014,70 @@
|
||||
return false;
|
||||
};
|
||||
|
||||
- match (window.tiled(), self.current_layout()) {
|
||||
- (_, WorkspaceLayout::Floating) | (false, _) => (),
|
||||
- // We only do interactive resizes on floating windows
|
||||
- (true, _) => return false,
|
||||
- }
|
||||
-
|
||||
+ // Tiled windows are resized by changing the layout (see handle_interactive_resize_motion)
|
||||
let loc = tile.visual_location();
|
||||
let size = window.size();
|
||||
+ let initial_proportion = tile.proportion();
|
||||
+ let initial_peers_proportion = self
|
||||
+ .stack_peers(window)
|
||||
+ .into_iter()
|
||||
+ .map(|idx| self.tiles[idx].proportion())
|
||||
+ .sum();
|
||||
self.interactive_resize = Some(InteractiveResize {
|
||||
window: window.clone(),
|
||||
initial_window_geometry: Rectangle::new(loc, size),
|
||||
edges,
|
||||
+ initial_mwfact: self.mwfact,
|
||||
+ initial_proportion,
|
||||
+ initial_peers_proportion,
|
||||
});
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
+ /// Get the indices of the other tiles that share a stack with this window in the current layout,
|
||||
+ /// IE. that split the stack's length with it according to their proportions.
|
||||
+ fn stack_peers(&self, window: &Window) -> Vec<usize> {
|
||||
+ // Matches how arrange_tiles orders and splits tiles.
|
||||
+ let tiled: Vec<usize> = (0..self.tiles.len())
|
||||
+ .filter(|&idx| {
|
||||
+ let window = self.tiles[idx].window();
|
||||
+ window.tiled() && !window.maximized()
|
||||
+ })
|
||||
+ .collect();
|
||||
+ let Some(position) = tiled
|
||||
+ .iter()
|
||||
+ .position(|&idx| self.tiles[idx].window() == window)
|
||||
+ else {
|
||||
+ return vec![];
|
||||
+ };
|
||||
+
|
||||
+ let nmaster = self.nmaster.min(tiled.len());
|
||||
+ let layout = self.current_layout();
|
||||
+ let same_stack = |other: usize| match layout {
|
||||
+ WorkspaceLayout::Tile | WorkspaceLayout::BottomStack => {
|
||||
+ (position < nmaster) == (other < nmaster)
|
||||
+ }
|
||||
+ // The non-master tiles alternate between the left and right stacks
|
||||
+ WorkspaceLayout::CenteredMaster => {
|
||||
+ if position < nmaster {
|
||||
+ other < nmaster
|
||||
+ } else {
|
||||
+ other >= nmaster && (other - nmaster) % 2 == (position - nmaster) % 2
|
||||
+ }
|
||||
+ }
|
||||
+ // The other layouts don't use proportions
|
||||
+ _ => false,
|
||||
+ };
|
||||
+
|
||||
+ tiled
|
||||
+ .into_iter()
|
||||
+ .enumerate()
|
||||
+ .filter(|&(other, _)| other != position && same_stack(other))
|
||||
+ .map(|(_, idx)| idx)
|
||||
+ .collect()
|
||||
+ }
|
||||
+
|
||||
/// Handle an interactive resize grab motion.
|
||||
///
|
||||
/// `delta` is how much the cursor moved from its initial window location.
|
||||
@@ -2052,11 +2104,53 @@
|
||||
return None;
|
||||
}
|
||||
|
||||
- match (window.tiled(), self.current_layout()) {
|
||||
- (_, WorkspaceLayout::Floating) | (false, _) => (),
|
||||
- // We switched from floating to tiled between the motion events
|
||||
- // Can happen if the user uses a key action bound to toggle-window-floating
|
||||
- (true, _) => return None,
|
||||
+ let layout = self.current_layout();
|
||||
+ if window.tiled() && layout != WorkspaceLayout::Floating {
|
||||
+ // For tiled windows, dragging along the master/stack split moves the split (mwfact)
|
||||
+ // so it follows the cursor, and dragging across it grows/shrinks the window in its
|
||||
+ // stack (proportion). Which axis is which depends on the layout.
|
||||
+ let initial_size = interactive_resize.initial_window_geometry.size;
|
||||
+ let work_area_size = self.work_area.size;
|
||||
+ let (split_delta, split_length, stack_delta, stack_length, grow_edge) = match layout {
|
||||
+ WorkspaceLayout::BottomStack => {
|
||||
+ (delta.y, work_area_size.h, delta.x, initial_size.w, ResizeEdge::LEFT)
|
||||
+ }
|
||||
+ _ => (delta.x, work_area_size.w, delta.y, initial_size.h, ResizeEdge::TOP),
|
||||
+ };
|
||||
+ // Grabbing the top (or left) part of the window grows it in that direction instead
|
||||
+ let stack_delta = if interactive_resize.edges.intersects(grow_edge) {
|
||||
+ -stack_delta
|
||||
+ } else {
|
||||
+ stack_delta
|
||||
+ };
|
||||
+
|
||||
+ let mwfact =
|
||||
+ interactive_resize.initial_mwfact + f64::from(split_delta) / f64::from(split_length.max(1));
|
||||
+
|
||||
+ // Solve for the proportion that gives the window exactly the length it was dragged to.
|
||||
+ // The other tiles in the stack keep their proportions (`peers`) during the drag, and
|
||||
+ // the window's length is `total * p / (p + peers)`, so `p = len * peers / (total - len)`
|
||||
+ let initial_proportion = interactive_resize.initial_proportion;
|
||||
+ let peers = interactive_resize.initial_peers_proportion;
|
||||
+ // Nothing to resize against if the window is alone in its stack
|
||||
+ if peers > 0.0 && initial_proportion > 0.0 && stack_length > 0 {
|
||||
+ let initial_length = f64::from(stack_length);
|
||||
+ let total_length = initial_length * (initial_proportion + peers) / initial_proportion;
|
||||
+ // Always leave some room for the window and the other tiles in the stack
|
||||
+ let min_length = (total_length * 0.05).max(1.0);
|
||||
+ let peer_count = self.stack_peers(window).len() as f64;
|
||||
+ let max_length = (total_length - min_length * peer_count.max(1.0)).max(min_length);
|
||||
+ let length = (initial_length + f64::from(stack_delta)).clamp(min_length, max_length);
|
||||
+ let proportion = length * peers / (total_length - length);
|
||||
+
|
||||
+ if let Some(tile) = self.tiles.iter_mut().find(|tile| tile.window() == window) {
|
||||
+ tile.set_proportion(proportion);
|
||||
+ }
|
||||
+ }
|
||||
+ // This also re-arranges the tiles
|
||||
+ self.set_mwfact(mwfact, false);
|
||||
+
|
||||
+ return Some(true);
|
||||
}
|
||||
|
||||
let mut new_size = interactive_resize.initial_window_geometry.size;
|
||||
@@ -2140,6 +2234,24 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
+ // Rescale the proportions in the window's stack so they average out to 1. This keeps the
|
||||
+ // same layout, but stops the values from drifting to extremes over repeated resizes,
|
||||
+ // where fixed steps (like change-window-proportion) would barely do anything anymore.
|
||||
+ if window.tiled() && self.current_layout() != WorkspaceLayout::Floating {
|
||||
+ let mut stack = self.stack_peers(window);
|
||||
+ if let Some(idx) = self.tiles.iter().position(|tile| tile.window() == window) {
|
||||
+ stack.push(idx);
|
||||
+ }
|
||||
+ let total: f64 = stack.iter().map(|&idx| self.tiles[idx].proportion()).sum();
|
||||
+ if stack.len() > 1 && total > 0.0 {
|
||||
+ let factor = stack.len() as f64 / total;
|
||||
+ for idx in stack {
|
||||
+ let proportion = self.tiles[idx].proportion();
|
||||
+ self.tiles[idx].set_proportion(proportion * factor);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
true
|
||||
}
|
||||
|
||||
--- a/src/input/actions.rs
|
||||
+++ b/src/input/actions.rs
|
||||
@@ -605,12 +605,8 @@
|
||||
}
|
||||
MouseAction::ResizeTile => {
|
||||
if let Some(window) = focus.and_then(|focus| focus.window) {
|
||||
+ // Tiled windows are resized too, by changing the workspace layout
|
||||
let workspace = self.fht.space.workspace_for_window(&window).unwrap();
|
||||
- match (window.tiled(), workspace.current_layout()) {
|
||||
- (_, WorkspaceLayout::Floating) | (false, _) => (),
|
||||
- // We only do interactive resizes on floating windows
|
||||
- (true, _) => return,
|
||||
- }
|
||||
|
||||
let pointer_loc = self.fht.pointer.current_location();
|
||||
let loc = self.fht.space.window_location(&window).unwrap().to_f64();
|
||||
Loading…
Reference in a new issue