diff --git a/README.md b/README.md index 10c35ccf..7818c36b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MangoWC -mango-transparency-256 +mango-transparency-256 This project's development is based on [dwl](https://codeberg.org/dwl/dwl/). @@ -32,11 +32,14 @@ Scroller Layout https://github.com/user-attachments/assets/c9bf9415-fad1-4400-bcdc-3ad2d76de85a -Layer animaiton +Layer animation https://github.com/user-attachments/assets/014c893f-115c-4ae9-8342-f9ae3e9a0df0 +# Our discord +[mangowc](https://discord.gg/CPjbDxesh5) + # Supported layouts - tile @@ -68,6 +71,8 @@ https://github.com/user-attachments/assets/014c893f-115c-4ae9-8342-f9ae3e9a0df0 - hwdata - seatd - pcre2 +- xorg-xwayland +- libxcb ## Arch Linux The package is in the Arch User Repository and is availble for manual download [here](https://aur.archlinux.org/packages/mangowc-git) or through a AUR helper like yay: @@ -77,7 +82,6 @@ yay -S mangowc-git ``` ## Gentoo Linux - The package is in the community-maintained repository called GURU. First, add GURU repository: @@ -95,15 +99,25 @@ Finally, install the package: emerge --ask --verbose gui-wm/mangowc ``` +## Fedora Linux +The package is in the third-party Terra repository. +First, add the [Terra Repository](https://terra.fyralabs.com/). + +Then, install the package: + +```bash +dnf install mangowc +``` + ## Other ```bash -git clone -b 0.19.1 https://gitlab.freedesktop.org/wlroots/wlroots.git +git clone -b 0.19.2 https://gitlab.freedesktop.org/wlroots/wlroots.git cd wlroots meson build -Dprefix=/usr sudo ninja -C build install -git clone https://github.com/wlrfx/scenefx.git +git clone -b 0.4.1 https://github.com/wlrfx/scenefx.git cd scenefx meson build -Dprefix=/usr sudo ninja -C build install @@ -116,6 +130,10 @@ sudo ninja -C build install ## Suggested Tools +### Hybrid component +- [dms-shell](https://github.com/AvengeMedia/DankMaterialShell) + +### Independent component - Application launcher (rofi, bemenu, wmenu, fuzzel) - Terminal emulator (foot, wezterm, alacritty, kitty, ghostty) - Status bar (waybar, eww, quickshell, ags), waybar is preferred @@ -136,13 +154,25 @@ sudo ninja -C build install ## My Dotfiles +### Daily - Dependencies ```bash yay -S rofi foot xdg-desktop-portal-wlr swaybg waybar wl-clip-persist cliphist wl-clipboard wlsunset xfce-polkit swaync pamixer wlr-dpms sway-audio-idle-inhibit-git swayidle dimland-git brightnessctl swayosd wlr-randr grim slurp satty swaylock-effects-git wlogout sox ``` -- use my config +### Dms +- Dependencies +```bash +yay -S foot xdg-desktop-portal-wlr swaybg wl-clip-persist cliphist wl-clipboard sway-audio-idle-inhibit-git brightnessctl grim slurp satty matugen-bin dms-shell-git + +``` +- use my dms config + +```bash +git clone -b dms https://github.com/DreamMaoMao/mango-config.git ~/.config/mango +``` +- use my daily config ```bash git clone https://github.com/DreamMaoMao/mango-config.git ~/.config/mango @@ -151,7 +181,9 @@ git clone https://github.com/DreamMaoMao/mango-config.git ~/.config/mango ## Config Documentation -Refer to the [wiki](https://github.com/DreamMaoMao/mango/wiki/) +Refer to the repo wiki [wiki](https://github.com/DreamMaoMao/mango/wiki/) + +or the website docs [docs](https://mangowc.vercel.app/docs) # NixOS + Home-manager @@ -170,7 +202,10 @@ Here's an example of using the modules in a flake: inputs.nixpkgs.follows = "nixpkgs"; }; flake-parts.url = "github:hercules-ci/flake-parts"; - mango.url = "github:DreamMaoMao/mango"; + mango = { + url = "github:DreamMaoMao/mango"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = inputs@{ self, flake-parts, ... }: @@ -226,14 +261,6 @@ Here's an example of using the modules in a flake: } ``` - -# Sponsor - -My current device is a bit outdated and doesn't support certain features like HDR or VRR. If you'd like to support this project, here's how you can help. Thanks! - -![Screenshot_2025-10-13-20-06-49-26_ee1cec40dcf6eb3](https://github.com/user-attachments/assets/240a0727-9eb5-4212-a84c-10fa9f093147) - - # Packaging mango To package mango for other distributions, you can check the reference setup for: diff --git a/assets/mango-black.png b/assets/mango-black.png deleted file mode 100644 index fabfe017..00000000 Binary files a/assets/mango-black.png and /dev/null differ diff --git a/assets/mango-transparency-128.png b/assets/mango-transparency-128.png index 7b9b4c64..a995f573 100644 Binary files a/assets/mango-transparency-128.png and b/assets/mango-transparency-128.png differ diff --git a/assets/mango-transparency-256.png b/assets/mango-transparency-256.png index 3bb4d653..974ab3f6 100644 Binary files a/assets/mango-transparency-256.png and b/assets/mango-transparency-256.png differ diff --git a/assets/mango-transparency.png b/assets/mango-transparency.png index 25e53856..488a31ec 100644 Binary files a/assets/mango-transparency.png and b/assets/mango-transparency.png differ diff --git a/assets/mango.png b/assets/mango.png index eb147404..5a8136f7 100644 Binary files a/assets/mango.png and b/assets/mango.png differ diff --git a/config.conf b/config.conf index 06fc49ae..5483a141 100644 --- a/config.conf +++ b/config.conf @@ -42,10 +42,14 @@ animation_duration_move=500 animation_duration_open=400 animation_duration_tag=350 animation_duration_close=800 +animation_duration_focus=0 animation_curve_open=0.46,1.0,0.29,1 animation_curve_move=0.46,1.0,0.29,1 animation_curve_tag=0.46,1.0,0.29,1 animation_curve_close=0.08,0.92,0,1 +animation_curve_focus=0.46,1.0,0.29,1 +animation_curve_opafadeout=0.5,0.5,0.5,0.5 +animation_curve_opafadein=0.46,1.0,0.29,1 # Scroller Layout Setting scroller_structs=20 @@ -73,7 +77,7 @@ overviewgappo=30 no_border_when_single=0 axis_bind_apply_timeout=100 focus_on_activate=1 -inhibit_regardless_of_visibility=0 +idleinhibit_ignore_visible=0 sloppyfocus=1 warpcursor=1 focus_cross_monitor=0 @@ -86,7 +90,7 @@ drag_tile_to_tile=1 # keyboard repeat_rate=25 repeat_delay=600 -numlockon=1 +numlockon=0 xkb_rules_layout=us # Trackpad @@ -116,7 +120,7 @@ borderpx=4 rootcolor=0x201b14ff bordercolor=0x444444ff focuscolor=0xc9b890ff -maxmizescreencolor=0x89aa61ff +maximizescreencolor=0x89aa61ff urgentcolor=0xad401fff scratchpadcolor=0x516c93ff globalcolor=0xb153a7ff @@ -166,7 +170,7 @@ bind=SUPER+SHIFT,Right,exchange_client,right bind=SUPER,g,toggleglobal, bind=ALT,Tab,toggleoverview, bind=ALT,backslash,togglefloating, -bind=ALT,a,togglemaxmizescreen, +bind=ALT,a,togglemaximizescreen, bind=ALT,f,togglefullscreen, bind=ALT+SHIFT,f,togglefakefullscreen, bind=SUPER,i,minimized, @@ -238,9 +242,9 @@ bind=CTRL+ALT,Right,resizewin,+50,+0 # Mouse Button Bindings # NONE mode key only work in ov mode mousebind=SUPER,btn_left,moveresize,curmove -mousebind=NONE,btn_middle,togglemaxmizescreen,0 +mousebind=NONE,btn_middle,togglemaximizescreen,0 mousebind=SUPER,btn_right,moveresize,curresize -mousebind=NONE,btn_left,toggleoverview,-1 +mousebind=NONE,btn_left,toggleoverview,1 mousebind=NONE,btn_right,killclient,0 # Axis Bindings diff --git a/flake.nix b/flake.nix index ff88ba0c..b7158bbd 100644 --- a/flake.nix +++ b/flake.nix @@ -30,7 +30,7 @@ }: let inherit (pkgs) callPackage ; mango = callPackage ./nix { - inherit (inputs.scenefx.packages.${pkgs.system}) scenefx; + inherit (inputs.scenefx.packages.${pkgs.stdenv.hostPlatform.system}) scenefx; }; shellOverride = old: { nativeBuildInputs = old.nativeBuildInputs ++ []; diff --git a/mangowc.scm b/mangowc.scm new file mode 100644 index 00000000..9c55d43e --- /dev/null +++ b/mangowc.scm @@ -0,0 +1,64 @@ +(define-module (mangowc) + #:use-module (guix download) + #:use-module (guix git-download) + #:use-module (guix gexp) + #:use-module (guix packages) + #:use-module (guix utils) + #:use-module (gnu packages wm) + #:use-module (gnu packages freedesktop) + #:use-module (gnu packages xdisorg) + #:use-module (gnu packages pciutils) + #:use-module (gnu packages admin) + #:use-module (gnu packages pcre) + #:use-module (gnu packages xorg) + #:use-module (gnu packages build-tools) + #:use-module (gnu packages ninja) + #:use-module (gnu packages pkg-config) + #:use-module (guix build-system meson) + #:use-module (guix licenses)) + + +(define-public mangowc-git + (package + (name "mangowc") + (version "git") + (source (local-file "." "mangowc-checkout" + #:recursive? #t + #:select? (or (git-predicate (current-source-directory)) + (const #t)))) + (build-system meson-build-system) + (arguments + (list + #:configure-flags + #~(list (string-append "-Dsysconfdir=" #$output "/etc")) + #:phases + #~(modify-phases %standard-phases + (add-before 'configure 'patch-meson + (lambda _ + (substitute* "meson.build" + (("'-DSYSCONFDIR=\\\"@0@\\\"'.format\\('/etc'\\)") + "'-DSYSCONFDIR=\"@0@\"'.format(sysconfdir)") + (("sysconfdir = sysconfdir.substring\\(prefix.length\\(\\)\\)") + ""))))))) + (inputs (list wayland + libinput + libdrm + libxkbcommon + pixman + libdisplay-info + libliftoff + hwdata + seatd + pcre2 + libxcb + xcb-util-wm + wlroots + scenefx)) + (native-inputs (list pkg-config wayland-protocols)) + (home-page "https://github.com/DreamMaoMao/mangowc") + (synopsis "Wayland compositor based on wlroots and scenefx") + (description "A Wayland compositor based on wlroots and scenefx, +inspired by dwl but aiming to be more feature-rich.") + (license gpl3))) + +mangowc-git diff --git a/meson.build b/meson.build index de992266..9f197ab1 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project('mango', ['c', 'cpp'], - version : '0.10.2', + version : '0.10.8', ) subdir('protocols') @@ -32,10 +32,10 @@ cc = meson.get_compiler('c') libm = cc.find_library('m') xcb = dependency('xcb', required : get_option('xwayland')) xlibs = dependency('xcb-icccm', required : get_option('xwayland')) -wayland_server_dep = dependency('wayland-server') +wayland_server_dep = dependency('wayland-server',version: '>=1.23.1') wlroots_dep = dependency('wlroots-0.19',version: '>=0.19.0') xkbcommon_dep = dependency('xkbcommon') -libinput_dep = dependency('libinput') +libinput_dep = dependency('libinput',version: '>=1.27.1') libwayland_client_dep = dependency('wayland-client') pcre2_dep = dependency('libpcre2-8') libscenefx_dep = dependency('scenefx-0.4',version: '>=0.4.1') diff --git a/mmsg/mmsg.c b/mmsg/mmsg.c index ae9270d7..2bbe870e 100644 --- a/mmsg/mmsg.c +++ b/mmsg/mmsg.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -40,6 +41,7 @@ static int xflag; static int eflag; static int kflag; static int bflag; +static int Aflag; static uint32_t occ, seltags, total_clients, urg; @@ -84,7 +86,7 @@ static void noop_description(void *data, struct wl_output *wl_output, const char *description) {} // 将 n 转换为 9 位二进制字符串,结果存入 buf(至少长度 10) -void bin_str_9bits(char *buf, unsigned int n) { +void bin_str_9bits(char *buf, uint32_t n) { for (int i = 8; i >= 0; i--) { *buf++ = ((n >> i) & 1) ? '1' : '0'; } @@ -263,6 +265,18 @@ static void dwl_ipc_output_kb_layout(void *data, printf("kb_layout %s\n", kb_layout); } +static void +dwl_ipc_output_scalefactor(void *data, + struct zdwl_ipc_output_v2 *dwl_ipc_output, + const uint32_t scalefactor) { + if (!Aflag) + return; + char *output_name = data; + if (output_name) + printf("%s ", output_name); + printf("scale_factor %f\n", scalefactor / 100.0f); +} + static void dwl_ipc_output_keymode(void *data, struct zdwl_ipc_output_v2 *dwl_ipc_output, const char *keymode) { @@ -373,6 +387,7 @@ static void dwl_ipc_output_frame(void *data, dispatch_arg3, dispatch_arg4, dispatch_arg5); } wl_display_flush(display); + usleep(1000); exit(0); } else { if (tflag) { @@ -411,6 +426,7 @@ static const struct zdwl_ipc_output_v2_listener dwl_ipc_output_listener = { .last_layer = dwl_ipc_output_last_layer, .kb_layout = dwl_ipc_output_kb_layout, .keymode = dwl_ipc_output_keymode, + .scalefactor = dwl_ipc_output_scalefactor, .frame = dwl_ipc_output_frame, }; @@ -488,7 +504,7 @@ static void usage(void) { "\t%s [-OTLq]\n" "\t%s [-o ] -s [-t ] [-l ] [-c ] [-d " ",,,,,]\n" - "\t%s [-o ] (-g | -w) [-Ootlcvmfxekb]\n", + "\t%s [-o ] (-g | -w) [-OotlcvmfxekbA]\n", argv0, argv0, argv0); exit(2); } @@ -730,6 +746,12 @@ int main(int argc, char *argv[]) { usage(); mode |= GET; break; + case 'A': + Aflag = 1; + if (mode == SET) + usage(); + mode |= GET; + break; default: fprintf(stderr, "bad option %c\n", ARGC()); usage(); @@ -739,9 +761,10 @@ int main(int argc, char *argv[]) { usage(); if (mode & GET && !output_name && !(oflag || tflag || lflag || Oflag || Tflag || Lflag || cflag || - vflag || mflag || fflag || xflag || eflag || kflag || bflag || dflag)) + vflag || mflag || fflag || xflag || eflag || kflag || bflag || + Aflag || dflag)) oflag = tflag = lflag = cflag = vflag = mflag = fflag = xflag = eflag = - kflag = bflag = 1; + kflag = bflag = Aflag = 1; display = wl_display_connect(NULL); if (!display) diff --git a/nix/default.nix b/nix/default.nix index b72977d3..6085565e 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -13,60 +13,64 @@ wayland-scanner, xcbutilwm, xwayland, - enableXWayland ? true, meson, ninja, scenefx, wlroots_0_19, libGL, -}: let + enableXWayland ? true, + debug ? false, +}: +stdenv.mkDerivation { pname = "mango"; -in - stdenv.mkDerivation { - inherit pname; - version = "nightly"; + version = "nightly"; - src = builtins.path { - path = ../.; - name = "source"; - }; + src = builtins.path { + path = ../.; + name = "source"; + }; - nativeBuildInputs = [ - meson - ninja - pkg-config - wayland-scanner + mesonFlags = [ + (lib.mesonEnable "xwayland" enableXWayland) + (lib.mesonBool "asan" debug) + ]; + + nativeBuildInputs = [ + meson + ninja + pkg-config + wayland-scanner + ]; + + buildInputs = + [ + libinput + libxcb + libxkbcommon + pcre2 + pixman + wayland + wayland-protocols + wlroots_0_19 + scenefx + libGL + ] + ++ lib.optionals enableXWayland [ + libX11 + xcbutilwm + xwayland ]; - buildInputs = - [ - libinput - libxcb - libxkbcommon - pcre2 - pixman - wayland - wayland-protocols - wlroots_0_19 - scenefx - libGL - ] - ++ lib.optionals enableXWayland [ - libX11 - xcbutilwm - xwayland - ]; + passthru = { + providedSessions = ["mango"]; + }; - passthru = { - providedSessions = ["mango"]; - }; - - meta = { - mainProgram = "mango"; - description = "A streamlined but feature-rich Wayland compositor"; - homepage = "https://github.com/DreamMaoMao/mango"; - license = lib.licenses.gpl3Plus; - maintainers = []; - platforms = lib.platforms.unix; - }; - } + meta = { + mainProgram = "mango"; + description = "A streamlined but feature-rich Wayland compositor"; + homepage = "https://github.com/DreamMaoMao/mango"; + license = lib.licenses.gpl3Plus; + maintainers = []; + platforms = lib.platforms.unix; + }; +} diff --git a/nix/hm-modules.nix b/nix/hm-modules.nix index 286f0cbb..85d57908 100644 --- a/nix/hm-modules.nix +++ b/nix/hm-modules.nix @@ -21,7 +21,7 @@ in { }; package = lib.mkOption { type = lib.types.package; - default = self.packages.${pkgs.system}.mango; + default = self.packages.${pkgs.stdenv.hostPlatform.system}.mango; description = "The mango package to use"; }; systemd = { diff --git a/nix/nixos-modules.nix b/nix/nixos-modules.nix index 9e73d6af..33811022 100644 --- a/nix/nixos-modules.nix +++ b/nix/nixos-modules.nix @@ -11,7 +11,7 @@ in { enable = lib.mkEnableOption "mango, a wayland compositor based on dwl"; package = lib.mkOption { type = lib.types.package; - default = self.packages.${pkgs.system}.mango; + default = self.packages.${pkgs.stdenv.hostPlatform.system}.mango; description = "The mango package to use"; }; }; @@ -26,6 +26,25 @@ in { xdg.portal = { enable = lib.mkDefault true; + config = { + mango = { + default = [ + "gtk" + ]; + # except those + "org.freedesktop.impl.portal.Secret" = ["gnome-keyring"]; + "org.freedesktop.impl.portal.ScreenCast" = ["wlr"]; + "org.freedesktop.impl.portal.ScreenShot" = ["wlr"]; + + # wlr does not have this interface + "org.freedesktop.impl.portal.Inhibit" = []; + }; + }; + extraPortals = with pkgs; [ + xdg-desktop-portal-wlr + xdg-desktop-portal-gtk + ]; + wlr.enable = lib.mkDefault true; configPackages = [cfg.package]; diff --git a/protocols/dwl-ipc-unstable-v2.xml b/protocols/dwl-ipc-unstable-v2.xml index a43a7f06..5852107e 100644 --- a/protocols/dwl-ipc-unstable-v2.xml +++ b/protocols/dwl-ipc-unstable-v2.xml @@ -241,6 +241,13 @@ I would probably just submit raphi's patchset but I don't think that would be po + + + scale factor of monitor. + + + + diff --git a/protocols/meson.build b/protocols/meson.build index 1069157c..cafab64a 100644 --- a/protocols/meson.build +++ b/protocols/meson.build @@ -19,6 +19,7 @@ wayland_xmls = [ wl_protocol_dir + '/staging/ext-image-capture-source/ext-image-capture-source-v1.xml', wl_protocol_dir + '/staging/ext-foreign-toplevel-list/ext-foreign-toplevel-list-v1.xml', wl_protocol_dir + '/staging/ext-workspace/ext-workspace-v1.xml', + wl_protocol_dir + '/staging/tearing-control/tearing-control-v1.xml', 'wlr-foreign-toplevel-management-unstable-v1.xml', 'dwl-ipc-unstable-v2.xml', 'wlr-layer-shell-unstable-v1.xml', diff --git a/src/animation/client.h b/src/animation/client.h index b7e3789b..596336f7 100644 --- a/src/animation/client.h +++ b/src/animation/client.h @@ -1,4 +1,4 @@ -void client_actual_size(Client *c, unsigned int *width, unsigned int *height) { +void client_actual_size(Client *c, uint32_t *width, uint32_t *height) { *width = c->animation.current.width - c->bw; *height = c->animation.current.height - c->bw; @@ -183,8 +183,8 @@ void scene_buffer_apply_effect(struct wlr_scene_buffer *buffer, int sx, int sy, if (buffer_data->should_scale) { - unsigned int surface_width = surface->current.width; - unsigned int surface_height = surface->current.height; + uint32_t surface_width = surface->current.width; + uint32_t surface_height = surface->current.height; surface_width = buffer_data->width_scale < 1 ? surface_width @@ -225,12 +225,6 @@ void scene_buffer_apply_effect(struct wlr_scene_buffer *buffer, int sx, int sy, wlr_scene_buffer_set_corner_radius(buffer, border_radius, buffer_data->corner_location); - - float target_opacity = buffer_data->percent + fadein_begin_opacity; - if (target_opacity > buffer_data->opacity) { - target_opacity = buffer_data->opacity; - } - wlr_scene_buffer_set_opacity(buffer, target_opacity); } void buffer_set_effect(Client *c, BufferData data) { @@ -246,8 +240,9 @@ void buffer_set_effect(Client *c, BufferData data) { if (c == grabc) data.should_scale = false; - if (c->isfullscreen || (no_radius_when_single && c->mon && - c->mon->visible_tiling_clients == 1)) { + if (c->isnoradius || c->isfullscreen || + (no_radius_when_single && c->mon && + c->mon->visible_tiling_clients == 1)) { data.corner_location = CORNER_LOCATION_NONE; } @@ -257,12 +252,16 @@ void buffer_set_effect(Client *c, BufferData data) { void client_draw_shadow(Client *c) { - if (c->iskilling || !client_surface(c)->mapped) + if (c->iskilling || !client_surface(c)->mapped || c->isnoshadow) return; if (!shadows || (!c->isfloating && shadow_only_floating)) { - wlr_scene_shadow_set_size(c->shadow, 0, 0); + if (c->shadow->node.enabled) + wlr_scene_node_set_enabled(&c->shadow->node, false); return; + } else { + if (c->scene_surface->node.enabled && !c->shadow->node.enabled) + wlr_scene_node_set_enabled(&c->shadow->node, true); } bool hit_no_border = check_hit_no_border(c); @@ -272,7 +271,7 @@ void client_draw_shadow(Client *c) { ? CORNER_LOCATION_NONE : CORNER_LOCATION_ALL; - unsigned int bwoffset = c->bw != 0 && hit_no_border ? c->bw : 0; + uint32_t bwoffset = c->bw != 0 && hit_no_border ? c->bw : 0; uint32_t width, height; client_actual_size(c, &width, &height); @@ -356,11 +355,13 @@ void apply_border(Client *c) { return; bool hit_no_border = check_hit_no_border(c); - enum corner_location current_corner_location = - c->isfullscreen || (no_radius_when_single && c->mon && - c->mon->visible_tiling_clients == 1) - ? CORNER_LOCATION_NONE - : CORNER_LOCATION_ALL; + enum corner_location current_corner_location; + if (c->isfullscreen || (no_radius_when_single && c->mon && + c->mon->visible_tiling_clients == 1)) { + current_corner_location = CORNER_LOCATION_NONE; + } else { + current_corner_location = set_client_corner_location(c); + } // Handle no-border cases if (hit_no_border && smartgaps) { @@ -448,7 +449,7 @@ struct ivec2 clip_to_hide(Client *c, struct wlr_box *clip_box) { int offsetx = 0, offsety = 0, offsetw = 0, offseth = 0; struct ivec2 offset = {0, 0, 0, 0}; - if (!ISTILED(c) && !c->animation.tagining && !c->animation.tagouted && + if (!ISSCROLLTILED(c) && !c->animation.tagining && !c->animation.tagouted && !c->animation.tagouting) return offset; @@ -469,7 +470,7 @@ struct ivec2 clip_to_hide(Client *c, struct wlr_box *clip_box) { 需要主要border超出屏幕的时候不计算如偏差之内而是 要等窗口表面超出才开始计算偏差 */ - if (ISTILED(c) || c->animation.tagining || c->animation.tagouted || + if (ISSCROLLTILED(c) || c->animation.tagining || c->animation.tagouted || c->animation.tagouting) { if (left_out_offset > 0) { offsetx = GEZERO(left_out_offset - bw); @@ -497,7 +498,7 @@ struct ivec2 clip_to_hide(Client *c, struct wlr_box *clip_box) { offset.height = offseth; if ((clip_box->width + bw <= 0 || clip_box->height + bw <= 0) && - (ISTILED(c) || c->animation.tagouting || c->animation.tagining)) { + (ISSCROLLTILED(c) || c->animation.tagouting || c->animation.tagining)) { c->is_clip_to_hide = true; wlr_scene_node_set_enabled(&c->scene->node, false); } else if (c->is_clip_to_hide && VISIBLEON(c, c->mon)) { @@ -517,7 +518,6 @@ void client_apply_clip(Client *c, float factor) { bool should_render_client_surface = false; struct ivec2 offset; BufferData buffer_data; - float opacity, percent; enum corner_location current_corner_location = set_client_corner_location(c); @@ -537,31 +537,19 @@ void client_apply_clip(Client *c, float factor) { apply_border(c); client_draw_shadow(c); - opacity = c->isfullscreen ? 1 - : c == selmon->sel ? c->focused_opacity - : c->unfocused_opacity; - if (clip_box.width <= 0 || clip_box.height <= 0) { return; } wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip_box); buffer_set_effect(c, (BufferData){1.0f, 1.0f, clip_box.width, - clip_box.height, opacity, opacity, + clip_box.height, current_corner_location, true}); return; } - percent = - c->animation.action == OPEN && animation_fade_in && !c->nofadein - ? (double)c->animation.passed_frames / c->animation.total_frames - : 1.0; - opacity = c->isfullscreen ? 1 - : c == selmon->sel ? c->focused_opacity - : c->unfocused_opacity; - // 获取窗口动画实时位置矩形 - unsigned int width, height; + uint32_t width, height; client_actual_size(c, &width, &height); // 计算出除了边框的窗口实际剪切大小 @@ -614,8 +602,6 @@ void client_apply_clip(Client *c, float factor) { buffer_data.width = clip_box.width; buffer_data.height = clip_box.height; buffer_data.corner_location = current_corner_location; - buffer_data.percent = percent; - buffer_data.opacity = opacity; if (factor == 1.0) { buffer_data.width_scale = 1.0; @@ -636,23 +622,28 @@ void fadeout_client_animation_next_tick(Client *c) { BufferData buffer_data; + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + + uint32_t passed_time = timespec_to_ms(&now) - c->animation.time_started; double animation_passed = - c->animation.total_frames - ? (double)c->animation.passed_frames / c->animation.total_frames + c->animation.duration + ? (double)passed_time / (double)c->animation.duration : 1.0; + int type = c->animation.action = c->animation.action; double factor = find_animation_curve_at(animation_passed, type); - unsigned int width = - c->animation.initial.width + - (c->current.width - c->animation.initial.width) * factor; - unsigned int height = + + uint32_t width = c->animation.initial.width + + (c->current.width - c->animation.initial.width) * factor; + uint32_t height = c->animation.initial.height + (c->current.height - c->animation.initial.height) * factor; - unsigned int x = c->animation.initial.x + - (c->current.x - c->animation.initial.x) * factor; - unsigned int y = c->animation.initial.y + - (c->current.y - c->animation.initial.y) * factor; + uint32_t x = c->animation.initial.x + + (c->current.x - c->animation.initial.x) * factor; + uint32_t y = c->animation.initial.y + + (c->current.y - c->animation.initial.y) * factor; wlr_scene_node_set_position(&c->scene->node, x, y); @@ -663,7 +654,13 @@ void fadeout_client_animation_next_tick(Client *c) { .height = height, }; - double opacity = MAX(fadeout_begin_opacity - animation_passed, 0); + double opacity_eased_progress = + find_animation_curve_at(animation_passed, OPAFADEOUT); + + double percent = fadeout_begin_opacity - + (opacity_eased_progress * fadeout_begin_opacity); + + double opacity = MAX(percent, 0); if (animation_fade_out && !c->nofadeout) wlr_scene_node_for_each_buffer(&c->scene->node, @@ -683,20 +680,22 @@ void fadeout_client_animation_next_tick(Client *c) { &c->scene->node, snap_scene_buffer_apply_effect, &buffer_data); } - if (animation_passed == 1.0) { + if (animation_passed >= 1.0) { wl_list_remove(&c->fadeout_link); wlr_scene_node_destroy(&c->scene->node); free(c); c = NULL; - } else { - c->animation.passed_frames++; } } void client_animation_next_tick(Client *c) { + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + + uint32_t passed_time = timespec_to_ms(&now) - c->animation.time_started; double animation_passed = - c->animation.total_frames - ? (double)c->animation.passed_frames / c->animation.total_frames + c->animation.duration + ? (double)passed_time / (double)c->animation.duration : 1.0; int type = c->animation.action == NONE ? MOVE : c->animation.action; @@ -706,17 +705,16 @@ void client_animation_next_tick(Client *c) { double sx = 0, sy = 0; struct wlr_surface *surface = NULL; - unsigned int width = - c->animation.initial.width + - (c->current.width - c->animation.initial.width) * factor; - unsigned int height = + uint32_t width = c->animation.initial.width + + (c->current.width - c->animation.initial.width) * factor; + uint32_t height = c->animation.initial.height + (c->current.height - c->animation.initial.height) * factor; - unsigned int x = c->animation.initial.x + - (c->current.x - c->animation.initial.x) * factor; - unsigned int y = c->animation.initial.y + - (c->current.y - c->animation.initial.y) * factor; + int32_t x = c->animation.initial.x + + (c->current.x - c->animation.initial.x) * factor; + int32_t y = c->animation.initial.y + + (c->current.y - c->animation.initial.y) * factor; wlr_scene_node_set_position(&c->scene->node, x, y); c->animation.current = (struct wlr_box){ @@ -728,7 +726,7 @@ void client_animation_next_tick(Client *c) { c->is_pending_open_animation = false; - if (animation_passed == 1.0) { + if (animation_passed >= 1.0) { // clear the open action state // To prevent him from being mistaken that @@ -756,8 +754,6 @@ void client_animation_next_tick(Client *c) { // end flush in next frame, not the current frame c->need_output_flush = false; - } else { - c->animation.passed_frames++; } client_apply_clip(c, factor); @@ -841,14 +837,12 @@ void init_fadeout_client(Client *c) { fadeout_cient->geom.height * zoom_end_ratio; } - fadeout_cient->animation.passed_frames = 0; - fadeout_cient->animation.total_frames = - fadeout_cient->animation.duration / all_output_frame_duration_ms(); + fadeout_cient->animation.time_started = get_now_in_ms(); wlr_scene_node_set_enabled(&fadeout_cient->scene->node, true); wl_list_insert(&fadeout_clients, &fadeout_cient->fadeout_link); // 请求刷新屏幕 - wlr_output_schedule_frame(c->mon->wlr_output); + request_fresh_all_monitors(); } void client_commit(Client *c) { @@ -860,30 +854,21 @@ void client_commit(Client *c) { } c->animation.initial = c->animainit_geom; - // 设置动画速度 - c->animation.passed_frames = 0; - c->animation.total_frames = - c->animation.duration / all_output_frame_duration_ms(); + c->animation.time_started = get_now_in_ms(); // 标记动画开始 c->animation.running = true; c->animation.should_animate = false; - } else { - // 如果动画没有开始,且被判定为不应该动画, - // 则设置总帧数为1,不然其他地方一旦获取动画 - // 进度,总帧数作为分母会造成除零 - // 比如动画类型为none的时候 - if (!c->animation.running) { - c->animation.passed_frames = 1; - c->animation.total_frames = 1; - } } // 请求刷新屏幕 - wlr_output_schedule_frame(c->mon->wlr_output); + request_fresh_all_monitors(); } void client_set_pending_state(Client *c) { + if (!c || c->iskilling) + return; + // 判断是否需要动画 if (!animations) { c->animation.should_animate = false; @@ -915,6 +900,11 @@ void client_set_pending_state(Client *c) { c->animation.duration = 0; } + if (c->isnoanimation) { + c->animation.should_animate = false; + c->animation.duration = 0; + } + // 开始动画 client_commit(c); c->dirty = true; @@ -951,7 +941,7 @@ void resize(Client *c, struct wlr_box geo, int interact) { bbox); // 去掉这个推荐的窗口大小,因为有时推荐的窗口特别大导致平铺异常 } - if (!c->isnosizehint && !c->ismaxmizescreen && !c->isfullscreen && + if (!c->isnosizehint && !c->ismaximizescreen && !c->isfullscreen && c->isfloating) { client_set_size_bound(c); } @@ -1048,22 +1038,162 @@ bool client_draw_fadeout_frame(Client *c) { return true; } +void client_set_focused_opacity_animation(Client *c) { + float *border_color = get_border_color(c); + + if (!animations) { + setborder_color(c); + return; + } + + c->opacity_animation.duration = animation_duration_focus; + memcpy(c->opacity_animation.target_border_color, border_color, + sizeof(c->opacity_animation.target_border_color)); + c->opacity_animation.target_opacity = c->focused_opacity; + c->opacity_animation.time_started = get_now_in_ms(); + if (c->opacity_animation.running) { + memcpy(c->opacity_animation.initial_border_color, + c->opacity_animation.current_border_color, + sizeof(c->opacity_animation.initial_border_color)); + c->opacity_animation.initial_opacity = + c->opacity_animation.current_opacity; + } else { + memcpy(c->opacity_animation.initial_border_color, border_color, + sizeof(c->opacity_animation.initial_border_color)); + memcpy(c->opacity_animation.current_border_color, border_color, + sizeof(c->opacity_animation.current_border_color)); + c->opacity_animation.initial_opacity = c->unfocused_opacity; + c->opacity_animation.current_opacity = c->unfocused_opacity; + } + c->opacity_animation.running = true; +} + +void client_set_unfocused_opacity_animation(Client *c) { + // Start border color animation to unfocused + float *border_color = get_border_color(c); + + if (!animations) { + setborder_color(c); + return; + } + + c->opacity_animation.duration = animation_duration_focus; + memcpy(c->opacity_animation.target_border_color, border_color, + sizeof(c->opacity_animation.target_border_color)); + // Start opacity animation to unfocused + c->opacity_animation.target_opacity = c->unfocused_opacity; + c->opacity_animation.time_started = get_now_in_ms(); + + if (c->opacity_animation.running) { + memcpy(c->opacity_animation.initial_border_color, + c->opacity_animation.current_border_color, + sizeof(c->opacity_animation.initial_border_color)); + c->opacity_animation.initial_opacity = + c->opacity_animation.current_opacity; + } else { + memcpy(c->opacity_animation.initial_border_color, border_color, + sizeof(c->opacity_animation.initial_border_color)); + memcpy(c->opacity_animation.current_border_color, border_color, + sizeof(c->opacity_animation.current_border_color)); + c->opacity_animation.initial_opacity = c->focused_opacity; + c->opacity_animation.current_opacity = c->focused_opacity; + } + + c->opacity_animation.running = true; +} + +bool client_apply_focus_opacity(Client *c) { + // Animate focus transitions (opacity + border color) + float *border_color = get_border_color(c); + if (c->isfullscreen) { + c->opacity_animation.running = false; + client_set_opacity(c, 1); + } else if (c->animation.running && c->animation.action == OPEN) { + c->opacity_animation.running = false; + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + + uint32_t passed_time = timespec_to_ms(&now) - c->animation.time_started; + double linear_progress = + c->animation.duration + ? (double)passed_time / (double)c->animation.duration + : 1.0; + + double opacity_eased_progress = + find_animation_curve_at(linear_progress, OPAFADEIN); + + float percent = + animation_fade_in && !c->nofadein ? opacity_eased_progress : 1.0; + float opacity = + c == selmon->sel ? c->focused_opacity : c->unfocused_opacity; + + float target_opacity = + percent * (1.0 - fadein_begin_opacity) + fadein_begin_opacity; + if (target_opacity > opacity) { + target_opacity = opacity; + } + client_set_opacity(c, target_opacity); + } else if (animations && c->opacity_animation.running) { + + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + + uint32_t passed_time = + timespec_to_ms(&now) - c->opacity_animation.time_started; + double linear_progress = + c->opacity_animation.duration + ? (double)passed_time / (double)c->opacity_animation.duration + : 1.0; + + float eased_progress = find_animation_curve_at(linear_progress, FOCUS); + + c->opacity_animation.current_opacity = + c->opacity_animation.initial_opacity + + (c->opacity_animation.target_opacity - + c->opacity_animation.initial_opacity) * + eased_progress; + client_set_opacity(c, c->opacity_animation.current_opacity); + + // Animate border color + for (int i = 0; i < 4; i++) { + c->opacity_animation.current_border_color[i] = + c->opacity_animation.initial_border_color[i] + + (c->opacity_animation.target_border_color[i] - + c->opacity_animation.initial_border_color[i]) * + eased_progress; + } + client_set_border_color(c, c->opacity_animation.current_border_color); + if (linear_progress == 1.0f) { + c->opacity_animation.running = false; + } else { + return true; + } + } else if (c == selmon->sel) { + c->opacity_animation.running = false; + c->opacity_animation.current_opacity = c->focused_opacity; + memcpy(c->opacity_animation.current_border_color, border_color, + sizeof(c->opacity_animation.current_border_color)); + client_set_opacity(c, c->focused_opacity); + } else { + c->opacity_animation.running = false; + c->opacity_animation.current_opacity = c->unfocused_opacity; + memcpy(c->opacity_animation.current_border_color, border_color, + sizeof(c->opacity_animation.current_border_color)); + client_set_opacity(c, c->unfocused_opacity); + } + + return false; +} + bool client_draw_frame(Client *c) { if (!c || !client_surface(c)->mapped) return false; - if (c->isfullscreen) { - client_set_opacity(c, 1); - } else if (c == selmon->sel && !c->animation.running) { - client_set_opacity(c, c->focused_opacity); - } else if (!c->animation.running) { - client_set_opacity(c, c->unfocused_opacity); + if (!c->need_output_flush) { + return client_apply_focus_opacity(c); } - if (!c->need_output_flush) - return false; - if (animations && c->animation.running) { client_animation_next_tick(c); } else { @@ -1074,5 +1204,6 @@ bool client_draw_frame(Client *c) { client_apply_clip(c, 1.0); c->need_output_flush = false; } + client_apply_focus_opacity(c); return true; } diff --git a/src/animation/common.h b/src/animation/common.h index 70a595c0..0f662d62 100644 --- a/src/animation/common.h +++ b/src/animation/common.h @@ -9,6 +9,12 @@ struct dvec2 calculate_animation_curve_at(double t, int type) { animation_curve = animation_curve_tag; } else if (type == CLOSE) { animation_curve = animation_curve_close; + } else if (type == FOCUS) { + animation_curve = animation_curve_focus; + } else if (type == OPAFADEIN) { + animation_curve = animation_curve_opafadein; + } else if (type == OPAFADEOUT) { + animation_curve = animation_curve_opafadeout; } else { animation_curve = animation_curve_move; } @@ -28,30 +34,48 @@ void init_baked_points(void) { baked_points_tag = calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_tag)); baked_points_close = calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_close)); + baked_points_focus = + calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_focus)); + baked_points_opafadein = + calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_opafadein)); + baked_points_opafadeout = + calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_opafadeout)); - for (unsigned int i = 0; i < BAKED_POINTS_COUNT; i++) { + for (uint32_t i = 0; i < BAKED_POINTS_COUNT; i++) { baked_points_move[i] = calculate_animation_curve_at( (double)i / (BAKED_POINTS_COUNT - 1), MOVE); } - for (unsigned int i = 0; i < BAKED_POINTS_COUNT; i++) { + for (uint32_t i = 0; i < BAKED_POINTS_COUNT; i++) { baked_points_open[i] = calculate_animation_curve_at( (double)i / (BAKED_POINTS_COUNT - 1), OPEN); } - for (unsigned int i = 0; i < BAKED_POINTS_COUNT; i++) { + for (uint32_t i = 0; i < BAKED_POINTS_COUNT; i++) { baked_points_tag[i] = calculate_animation_curve_at( (double)i / (BAKED_POINTS_COUNT - 1), TAG); } - for (unsigned int i = 0; i < BAKED_POINTS_COUNT; i++) { + for (uint32_t i = 0; i < BAKED_POINTS_COUNT; i++) { baked_points_close[i] = calculate_animation_curve_at( (double)i / (BAKED_POINTS_COUNT - 1), CLOSE); } + for (uint32_t i = 0; i < BAKED_POINTS_COUNT; i++) { + baked_points_focus[i] = calculate_animation_curve_at( + (double)i / (BAKED_POINTS_COUNT - 1), FOCUS); + } + for (uint32_t i = 0; i < BAKED_POINTS_COUNT; i++) { + baked_points_opafadein[i] = calculate_animation_curve_at( + (double)i / (BAKED_POINTS_COUNT - 1), OPAFADEIN); + } + for (uint32_t i = 0; i < BAKED_POINTS_COUNT; i++) { + baked_points_opafadeout[i] = calculate_animation_curve_at( + (double)i / (BAKED_POINTS_COUNT - 1), OPAFADEOUT); + } } double find_animation_curve_at(double t, int type) { - unsigned int down = 0; - unsigned int up = BAKED_POINTS_COUNT - 1; + uint32_t down = 0; + uint32_t up = BAKED_POINTS_COUNT - 1; - unsigned int middle = (up + down) / 2; + uint32_t middle = (up + down) / 2; struct dvec2 *baked_points; if (type == MOVE) { baked_points = baked_points_move; @@ -61,6 +85,12 @@ double find_animation_curve_at(double t, int type) { baked_points = baked_points_tag; } else if (type == CLOSE) { baked_points = baked_points_close; + } else if (type == FOCUS) { + baked_points = baked_points_focus; + } else if (type == OPAFADEIN) { + baked_points = baked_points_opafadein; + } else if (type == OPAFADEOUT) { + baked_points = baked_points_opafadeout; } else { baked_points = baked_points_move; } @@ -76,22 +106,6 @@ double find_animation_curve_at(double t, int type) { return baked_points[up].y; } -double all_output_frame_duration_ms() { - int32_t refresh_total = 0; - Monitor *m = NULL; - wl_list_for_each(m, &mons, link) { - if (!m->wlr_output->enabled) { - continue; - } - refresh_total += m->wlr_output->refresh; - } - return 1000000.0 / refresh_total; -} - -double output_frame_duration_ms(Monitor *m) { - return 1000000.0 / m->wlr_output->refresh; -} - static bool scene_node_snapshot(struct wlr_scene_node *node, int lx, int ly, struct wlr_scene_tree *snapshot_tree) { if (!node->enabled && node->type != WLR_SCENE_NODE_TREE) { @@ -234,4 +248,14 @@ struct wlr_scene_tree *wlr_scene_tree_snapshot(struct wlr_scene_node *node, wlr_scene_node_set_enabled(&snapshot->node, true); return snapshot; +} + +void request_fresh_all_monitors(void) { + Monitor *m = NULL; + wl_list_for_each(m, &mons, link) { + if (!m->wlr_output->enabled) { + continue; + } + wlr_output_schedule_frame(m->wlr_output); + } } \ No newline at end of file diff --git a/src/animation/layer.h b/src/animation/layer.h index 3b81fc2b..57e0c149 100644 --- a/src/animation/layer.h +++ b/src/animation/layer.h @@ -1,5 +1,4 @@ -void layer_actual_size(LayerSurface *l, unsigned int *width, - unsigned int *height) { +void layer_actual_size(LayerSurface *l, uint32_t *width, uint32_t *height) { struct wlr_box box; if (l->animation.running) { @@ -213,9 +212,8 @@ void layer_scene_buffer_apply_effect(struct wlr_scene_buffer *buffer, int sx, struct wlr_surface *surface = scene_surface->surface; - unsigned int surface_width = - surface->current.width * buffer_data->width_scale; - unsigned int surface_height = + uint32_t surface_width = surface->current.width * buffer_data->width_scale; + uint32_t surface_height = surface->current.height * buffer_data->height_scale; if (surface_height > 0 && surface_width > 0) { @@ -234,23 +232,27 @@ void fadeout_layer_animation_next_tick(LayerSurface *l) { if (!l) return; + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + + uint32_t passed_time = timespec_to_ms(&now) - l->animation.time_started; double animation_passed = - l->animation.total_frames - ? (double)l->animation.passed_frames / l->animation.total_frames + l->animation.duration + ? (double)passed_time / (double)l->animation.duration : 1.0; + int type = l->animation.action = l->animation.action; double factor = find_animation_curve_at(animation_passed, type); - unsigned int width = - l->animation.initial.width + - (l->current.width - l->animation.initial.width) * factor; - unsigned int height = + uint32_t width = l->animation.initial.width + + (l->current.width - l->animation.initial.width) * factor; + uint32_t height = l->animation.initial.height + (l->current.height - l->animation.initial.height) * factor; - unsigned int x = l->animation.initial.x + - (l->current.x - l->animation.initial.x) * factor; - unsigned int y = l->animation.initial.y + - (l->current.y - l->animation.initial.y) * factor; + uint32_t x = l->animation.initial.x + + (l->current.x - l->animation.initial.x) * factor; + uint32_t y = l->animation.initial.y + + (l->current.y - l->animation.initial.y) * factor; wlr_scene_node_set_position(&l->scene->node, x, y); @@ -274,19 +276,23 @@ void fadeout_layer_animation_next_tick(LayerSurface *l) { .height = height, }; - double opacity = MAX(fadeout_begin_opacity - animation_passed, 0.0f); + double opacity_eased_progress = + find_animation_curve_at(animation_passed, OPAFADEOUT); + + double percent = fadeout_begin_opacity - + (opacity_eased_progress * fadeout_begin_opacity); + + double opacity = MAX(percent, 0.0f); if (animation_fade_out) wlr_scene_node_for_each_buffer(&l->scene->node, scene_buffer_apply_opacity, &opacity); - if (animation_passed == 1.0) { + if (animation_passed >= 1.0) { wl_list_remove(&l->fadeout_link); wlr_scene_node_destroy(&l->scene->node); free(l); l = NULL; - } else { - l->animation.passed_frames++; } } @@ -295,27 +301,36 @@ void layer_animation_next_tick(LayerSurface *l) { if (!l || !l->mapped) return; + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + + uint32_t passed_time = timespec_to_ms(&now) - l->animation.time_started; double animation_passed = - l->animation.total_frames - ? (double)l->animation.passed_frames / l->animation.total_frames + l->animation.duration + ? (double)passed_time / (double)l->animation.duration : 1.0; int type = l->animation.action == NONE ? MOVE : l->animation.action; double factor = find_animation_curve_at(animation_passed, type); - unsigned int width = - l->animation.initial.width + - (l->current.width - l->animation.initial.width) * factor; - unsigned int height = + uint32_t width = l->animation.initial.width + + (l->current.width - l->animation.initial.width) * factor; + uint32_t height = l->animation.initial.height + (l->current.height - l->animation.initial.height) * factor; - unsigned int x = l->animation.initial.x + - (l->current.x - l->animation.initial.x) * factor; - unsigned int y = l->animation.initial.y + - (l->current.y - l->animation.initial.y) * factor; + uint32_t x = l->animation.initial.x + + (l->current.x - l->animation.initial.x) * factor; + uint32_t y = l->animation.initial.y + + (l->current.y - l->animation.initial.y) * factor; - double opacity = MIN(fadein_begin_opacity + animation_passed, 1.0f); + double opacity_eased_progress = + find_animation_curve_at(animation_passed, OPAFADEIN); + + double opacity = + MIN(fadein_begin_opacity + + opacity_eased_progress * (1.0 - fadein_begin_opacity), + 1.0f); if (animation_fade_in) wlr_scene_node_for_each_buffer(&l->scene->node, @@ -347,12 +362,10 @@ void layer_animation_next_tick(LayerSurface *l) { .height = height, }; - if (animation_passed == 1.0) { + if (animation_passed >= 1.0) { l->animation.running = false; l->need_output_flush = false; l->animation.action = MOVE; - } else { - l->animation.passed_frames++; } } @@ -446,10 +459,8 @@ void init_fadeout_layers(LayerSurface *l) { fadeout_layer->current.height = 0; } - // 计算动画帧数 - fadeout_layer->animation.passed_frames = 0; - fadeout_layer->animation.total_frames = - fadeout_layer->animation.duration / all_output_frame_duration_ms(); + // 动画开始时间 + fadeout_layer->animation.time_started = get_now_in_ms(); // 将节点插入到关闭动画链表中,屏幕刷新哪里会检查链表中是否有节点可以应用于动画 wlr_scene_node_set_enabled(&fadeout_layer->scene->node, true); @@ -532,23 +543,11 @@ void layer_commit(LayerSurface *l) { } l->animation.initial = l->animainit_geom; - // 设置动画速度 - l->animation.passed_frames = 0; - l->animation.total_frames = - l->animation.duration / output_frame_duration_ms(l->mon); + l->animation.time_started = get_now_in_ms(); // 标记动画开始 l->animation.running = true; l->animation.should_animate = false; - } else { - // 如果动画没有开始,且被判定为不应该动画, - // 则设置总帧数为1,不然其他地方一旦获取动画 - // 进度,总帧数作为分母会造成除零 - // 比如动画类型为none的时候 - if (!l->animation.running) { - l->animation.passed_frames = 1; - l->animation.total_frames = 1; - } } // 请求刷新屏幕 wlr_output_schedule_frame(l->mon->wlr_output); diff --git a/src/animation/tag.h b/src/animation/tag.h index cd13237d..8e65a93a 100644 --- a/src/animation/tag.h +++ b/src/animation/tag.h @@ -9,19 +9,23 @@ void set_tagin_animation(Monitor *m, Client *c) { c->animainit_geom.x = tag_animation_direction == VERTICAL ? c->animation.current.x - : c->geom.x + c->mon->m.width; + : MAX(c->mon->m.x + c->mon->m.width, + c->geom.x + c->mon->m.width); c->animainit_geom.y = tag_animation_direction == VERTICAL - ? c->geom.y + c->mon->m.height + ? MAX(c->mon->m.y + c->mon->m.height, + c->geom.y + c->mon->m.height) : c->animation.current.y; } else { - c->animainit_geom.x = tag_animation_direction == VERTICAL - ? c->animation.current.x - : c->geom.x - c->mon->m.width; - c->animainit_geom.y = tag_animation_direction == VERTICAL - ? c->geom.y - c->mon->m.height - : c->animation.current.y; + c->animainit_geom.x = + tag_animation_direction == VERTICAL + ? c->animation.current.x + : MIN(m->m.x - c->geom.width, c->geom.x - c->mon->m.width); + c->animainit_geom.y = + tag_animation_direction == VERTICAL + ? MIN(m->m.y - c->geom.height, c->geom.y - c->mon->m.height) + : c->animation.current.y; } } @@ -52,11 +56,13 @@ void set_arrange_visible(Monitor *m, Client *c, bool want_animation) { void set_tagout_animation(Monitor *m, Client *c) { if (m->pertag->curtag > m->pertag->prevtag) { c->pending = c->geom; - c->pending.x = tag_animation_direction == VERTICAL - ? c->animation.current.x - : c->geom.x - c->mon->m.width; + c->pending.x = + tag_animation_direction == VERTICAL + ? c->animation.current.x + : MIN(c->mon->m.x - c->geom.width, c->geom.x - c->mon->m.width); c->pending.y = tag_animation_direction == VERTICAL - ? c->geom.y - c->mon->m.height + ? MIN(c->mon->m.y - c->geom.height, + c->geom.y - c->mon->m.height) : c->animation.current.y; resize(c, c->geom, 0); @@ -64,9 +70,11 @@ void set_tagout_animation(Monitor *m, Client *c) { c->pending = c->geom; c->pending.x = tag_animation_direction == VERTICAL ? c->animation.current.x - : c->geom.x + c->mon->m.width; + : MAX(c->mon->m.x + c->mon->m.width, + c->geom.x + c->mon->m.width); c->pending.y = tag_animation_direction == VERTICAL - ? c->geom.y + c->mon->m.height + ? MAX(c->mon->m.y + c->mon->m.height, + c->geom.y + c->mon->m.height) : c->animation.current.y; resize(c, c->geom, 0); } diff --git a/src/client/client.h b/src/client/client.h index 90be17e0..bc7706d7 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -359,7 +359,7 @@ static inline void client_set_maximized(Client *c, bool maximized) { static inline void client_set_tiled(Client *c, uint32_t edges) { struct wlr_xdg_toplevel *toplevel; #ifdef XWAYLAND - if (client_is_x11(c)) { + if (client_is_x11(c) && c->force_maximize) { wlr_xwayland_surface_set_maximized(c->surface.xwayland, edges != WLR_EDGE_NONE, edges != WLR_EDGE_NONE); @@ -374,7 +374,7 @@ static inline void client_set_tiled(Client *c, uint32_t edges) { wlr_xdg_toplevel_set_tiled(c->surface.xdg->toplevel, edges); } - if (!c->ignore_maximize && c->force_maximize) { + if (c->force_maximize) { wlr_xdg_toplevel_set_maximized(toplevel, edges != WLR_EDGE_NONE); } } @@ -390,6 +390,21 @@ static inline void client_set_suspended(Client *c, int suspended) { static inline int client_should_ignore_focus(Client *c) { +#ifdef XWAYLAND + if (client_is_x11(c)) { + struct wlr_xwayland_surface *surface = c->surface.xwayland; + + if (!surface->hints) + return 0; + + return !surface->hints->input; + } +#endif + return 0; +} + +static inline int client_is_x11_popup(Client *c) { + #ifdef XWAYLAND if (client_is_x11(c)) { struct wlr_xwayland_surface *surface = c->surface.xwayland; @@ -473,6 +488,18 @@ static inline bool client_request_minimize(Client *c, void *data) { return c->surface.xdg->toplevel->requested.minimized; } +static inline bool client_request_maximize(Client *c, void *data) { + +#ifdef XWAYLAND + if (client_is_x11(c)) { + struct wlr_xwayland_surface *surface = c->surface.xwayland; + return surface->maximized_vert || surface->maximized_horz; + } +#endif + + return c->surface.xdg->toplevel->requested.maximized; +} + static inline void client_set_size_bound(Client *c) { struct wlr_xdg_toplevel *toplevel; struct wlr_xdg_toplevel_state state; @@ -485,16 +512,16 @@ static inline void client_set_size_bound(Client *c) { if (!size_hints) return; - if ((unsigned int)c->geom.width - 2 * c->bw < size_hints->min_width && + if ((uint32_t)c->geom.width - 2 * c->bw < size_hints->min_width && size_hints->min_width > 0) c->geom.width = size_hints->min_width + 2 * c->bw; - if ((unsigned int)c->geom.height - 2 * c->bw < size_hints->min_height && + if ((uint32_t)c->geom.height - 2 * c->bw < size_hints->min_height && size_hints->min_height > 0) c->geom.height = size_hints->min_height + 2 * c->bw; - if ((unsigned int)c->geom.width - 2 * c->bw > size_hints->max_width && + if ((uint32_t)c->geom.width - 2 * c->bw > size_hints->max_width && size_hints->max_width > 0) c->geom.width = size_hints->max_width + 2 * c->bw; - if ((unsigned int)c->geom.height - 2 * c->bw > size_hints->max_height && + if ((uint32_t)c->geom.height - 2 * c->bw > size_hints->max_height && size_hints->max_height > 0) c->geom.height = size_hints->max_height + 2 * c->bw; return; @@ -503,19 +530,19 @@ static inline void client_set_size_bound(Client *c) { toplevel = c->surface.xdg->toplevel; state = toplevel->current; - if ((unsigned int)c->geom.width - 2 * c->bw < state.min_width && + if ((uint32_t)c->geom.width - 2 * c->bw < state.min_width && state.min_width > 0) { c->geom.width = state.min_width + 2 * c->bw; } - if ((unsigned int)c->geom.height - 2 * c->bw < state.min_height && + if ((uint32_t)c->geom.height - 2 * c->bw < state.min_height && state.min_height > 0) { c->geom.height = state.min_height + 2 * c->bw; } - if ((unsigned int)c->geom.width - 2 * c->bw > state.max_width && + if ((uint32_t)c->geom.width - 2 * c->bw > state.max_width && state.max_width > 0) { c->geom.width = state.max_width + 2 * c->bw; } - if ((unsigned int)c->geom.height - 2 * c->bw > state.max_height && + if ((uint32_t)c->geom.height - 2 * c->bw > state.max_height && state.max_height > 0) { c->geom.height = state.max_height + 2 * c->bw; } diff --git a/src/common/util.c b/src/common/util.c index 272340cd..79972054 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "util.h" @@ -80,3 +81,14 @@ int regex_match(const char *pattern, const char *str) { void wl_list_append(struct wl_list *list, struct wl_list *object) { wl_list_insert(list->prev, object); } + +uint32_t get_now_in_ms(void) { + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + + return timespec_to_ms(&now); +} + +uint32_t timespec_to_ms(struct timespec *ts) { + return (uint32_t)ts->tv_sec * 1000 + (uint32_t)ts->tv_nsec / 1000000; +} diff --git a/src/common/util.h b/src/common/util.h index 2ebef43a..2718eae8 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -6,3 +6,5 @@ void *ecalloc(size_t nmemb, size_t size); int fd_set_nonblock(int fd); int regex_match(const char *pattern_mb, const char *str_mb); void wl_list_append(struct wl_list *list, struct wl_list *object); +uint32_t get_now_in_ms(void); +uint32_t timespec_to_ms(struct timespec *ts); \ No newline at end of file diff --git a/src/config/parse_config.h b/src/config/parse_config.h index e4f00b1d..074b5227 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -18,11 +19,17 @@ enum { NUM_TYPE_MINUS, NUM_TYPE_PLUS, NUM_TYPE_DEFAULT }; -enum { KEY_TYPE_SYM, KEY_TYPE_CODE }; +enum { KEY_TYPE_CODE, KEY_TYPE_SYM }; + +typedef struct { + uint32_t keycode1; + uint32_t keycode2; + uint32_t keycode3; +} MultiKeycode; typedef struct { xkb_keysym_t keysym; - uint32_t keycode; + MultiKeycode keycode; int type; } KeySymCode; @@ -34,6 +41,9 @@ typedef struct { char mode[28]; bool iscommonmode; bool isdefaultmode; + bool islockapply; + bool isreleaseapply; + bool ispassapply; } KeyBinding; typedef struct { @@ -44,7 +54,7 @@ typedef struct { typedef struct { const char *id; const char *title; - unsigned int tags; + uint32_t tags; int isfloating; int isfullscreen; float scroller_proportion; @@ -53,12 +63,16 @@ typedef struct { const char *layer_animation_type_open; const char *layer_animation_type_close; int isnoborder; + int isnoshadow; + int isnoradius; + int isnoanimation; int isopensilent; int istagsilent; int isnamedscratchpad; int isunglobal; int isglobal; int isoverlay; + int allow_shortcuts_inhibit; int ignore_maximize; int ignore_minimize; int isnosizehint; @@ -67,16 +81,19 @@ typedef struct { int offsety; int width; int height; + int nofocus; int nofadein; int nofadeout; int no_force_center; int isterm; int allow_csd; int force_maximize; + int force_tearing; int noswallow; int noblur; float focused_opacity; float unfocused_opacity; + float scroller_proportion_single; uint32_t passmod; xkb_keysym_t keysym; KeyBinding globalkeybinding; @@ -110,29 +127,29 @@ KeyBinding default_key_bindings[] = {CHVT(1), CHVT(2), CHVT(3), CHVT(4), CHVT(9), CHVT(10), CHVT(11), CHVT(12)}; typedef struct { - unsigned int mod; - unsigned int button; + uint32_t mod; + uint32_t button; int (*func)(const Arg *); Arg arg; } MouseBinding; typedef struct { - unsigned int mod; - unsigned int dir; + uint32_t mod; + uint32_t dir; int (*func)(const Arg *); Arg arg; } AxisBinding; typedef struct { - unsigned int fold; + uint32_t fold; int (*func)(const Arg *); Arg arg; } SwitchBinding; typedef struct { - unsigned int mod; - unsigned int motion; - unsigned int fingers_count; + uint32_t mod; + uint32_t motion; + uint32_t fingers_count; int (*func)(const Arg *); Arg arg; } GestureBinding; @@ -172,14 +189,19 @@ typedef struct { uint32_t animation_duration_open; uint32_t animation_duration_tag; uint32_t animation_duration_close; + uint32_t animation_duration_focus; double animation_curve_move[4]; double animation_curve_open[4]; double animation_curve_tag[4]; double animation_curve_close[4]; + double animation_curve_focus[4]; + double animation_curve_opafadein[4]; + double animation_curve_opafadeout[4]; int scroller_structs; float scroller_default_proportion; float scroller_default_proportion_single; + int scroller_ignore_proportion_single; int scroller_focus_center; int scroller_prefer_center; int edge_scroller_pointer_focus; @@ -193,7 +215,7 @@ typedef struct { int snap_distance; int enable_floating_snap; int drag_tile_to_tile; - unsigned int swipe_min_threshold; + uint32_t swipe_min_threshold; float focused_opacity; float unfocused_opacity; float *scroller_proportion_preset; @@ -202,29 +224,29 @@ typedef struct { char **circle_layout; int circle_layout_count; - unsigned int new_is_master; + uint32_t new_is_master; float default_mfact; - unsigned int default_nmaster; + uint32_t default_nmaster; int center_master_overspread; int center_when_single_stack; - unsigned int hotarea_size; - unsigned int enable_hotarea; - unsigned int ov_tab_mode; + uint32_t hotarea_size; + uint32_t enable_hotarea; + uint32_t ov_tab_mode; int overviewgappi; int overviewgappo; - unsigned int cursor_hide_timeout; + uint32_t cursor_hide_timeout; - unsigned int axis_bind_apply_timeout; - unsigned int focus_on_activate; - int inhibit_regardless_of_visibility; + uint32_t axis_bind_apply_timeout; + uint32_t focus_on_activate; + int idleinhibit_ignore_visible; int sloppyfocus; int warpcursor; /* keyboard */ int repeat_rate; int repeat_delay; - unsigned int numlockon; + uint32_t numlockon; /* Trackpad */ int disable_trackpad; @@ -236,13 +258,15 @@ typedef struct { int disable_while_typing; int left_handed; int middle_button_emulation; - unsigned int accel_profile; + uint32_t accel_profile; double accel_speed; - unsigned int scroll_method; - unsigned int scroll_button; - unsigned int click_method; - unsigned int send_events_mode; - unsigned int button_map; + uint32_t scroll_method; + uint32_t scroll_button; + uint32_t click_method; + uint32_t send_events_mode; + uint32_t button_map; + + double axis_scroll_factor; int blur; int blur_layer; @@ -252,24 +276,24 @@ typedef struct { int shadows; int shadow_only_floating; int layer_shadows; - unsigned int shadows_size; + uint32_t shadows_size; float shadows_blur; int shadows_position_x; int shadows_position_y; float shadowscolor[4]; int smartgaps; - unsigned int gappih; - unsigned int gappiv; - unsigned int gappoh; - unsigned int gappov; - unsigned int borderpx; + uint32_t gappih; + uint32_t gappiv; + uint32_t gappoh; + uint32_t gappov; + uint32_t borderpx; float scratchpad_width_ratio; float scratchpad_height_ratio; float rootcolor[4]; float bordercolor[4]; float focuscolor[4]; - float maxmizescreencolor[4]; + float maximizescreencolor[4]; float urgentcolor[4]; float scratchpadcolor[4]; float globalcolor[4]; @@ -314,17 +338,22 @@ typedef struct { int exec_once_count; char *cursor_theme; - unsigned int cursor_size; + uint32_t cursor_size; int single_scratchpad; int xwayland_persistence; int syncobj_enable; int adaptive_sync; + int allow_tearing; + int allow_shortcuts_inhibit; + int allow_lock_transparent; struct xkb_rule_names xkb_rules; char keymode[28]; + struct xkb_context *ctx; + struct xkb_keymap *keymap; } Config; typedef int (*FuncType)(const Arg *); @@ -398,6 +427,38 @@ char *sanitize_string(char *str) { return str; } +// 解析bind组合字符串 +void parse_bind_flags(const char *str, KeyBinding *kb) { + + // 检查是否以"bind"开头 + if (strncmp(str, "bind", 4) != 0) { + return; + } + + const char *suffix = str + 4; // 跳过"bind" + + // 遍历后缀字符 + for (int i = 0; suffix[i] != '\0'; i++) { + switch (suffix[i]) { + case 's': + kb->keysymcode.type = KEY_TYPE_SYM; + break; + case 'l': + kb->islockapply = true; + break; + case 'r': + kb->isreleaseapply = true; + break; + case 'p': + kb->ispassapply = true; + break; + default: + // 忽略其他字符或可根据需要处理错误 + break; + } + } +} + int parse_circle_direction(const char *str) { // 将输入字符串转换为小写 char lowerStr[10]; @@ -468,61 +529,6 @@ long int parse_color(const char *hex_str) { return hex_num; } -xkb_keysym_t normalize_keysym(xkb_keysym_t sym) { - // 首先转换为小写(主要影响字母键) - sym = xkb_keysym_to_lower(sym); - - // 将数字小键盘键转换为普通数字键 - switch (sym) { - // 小键盘数字转换 - case XKB_KEY_KP_0: - return XKB_KEY_0; - case XKB_KEY_KP_1: - return XKB_KEY_1; - case XKB_KEY_KP_2: - return XKB_KEY_2; - case XKB_KEY_KP_3: - return XKB_KEY_3; - case XKB_KEY_KP_4: - return XKB_KEY_4; - case XKB_KEY_KP_5: - return XKB_KEY_5; - case XKB_KEY_KP_6: - return XKB_KEY_6; - case XKB_KEY_KP_7: - return XKB_KEY_7; - case XKB_KEY_KP_8: - return XKB_KEY_8; - case XKB_KEY_KP_9: - return XKB_KEY_9; - - // 将 Shift+数字 的符号转换回基础数字 - case XKB_KEY_exclam: - return XKB_KEY_1; // ! - case XKB_KEY_at: - return XKB_KEY_2; // @ - case XKB_KEY_numbersign: - return XKB_KEY_3; // # - case XKB_KEY_dollar: - return XKB_KEY_4; // $ - case XKB_KEY_percent: - return XKB_KEY_5; // % - case XKB_KEY_asciicircum: - return XKB_KEY_6; // ^ - case XKB_KEY_ampersand: - return XKB_KEY_7; // & - case XKB_KEY_asterisk: - return XKB_KEY_8; // * - case XKB_KEY_parenleft: - return XKB_KEY_9; // ( - case XKB_KEY_parenright: - return XKB_KEY_0; // ) - - default: - return sym; - } -} - // 辅助函数:检查字符串是否以指定的前缀开头(忽略大小写) static bool starts_with_ignore_case(const char *str, const char *prefix) { while (*prefix) { @@ -613,23 +619,120 @@ uint32_t parse_mod(const char *mod_str) { return mod; } -KeySymCode parse_key(const char *key_str) { - KeySymCode kc; +// 定义辅助函数:在 keymap 中查找 keysym 对应的多个 keycode +static int find_keycodes_for_keysym(struct xkb_keymap *keymap, xkb_keysym_t sym, + MultiKeycode *multi_kc) { + xkb_keycode_t min_keycode = xkb_keymap_min_keycode(keymap); + xkb_keycode_t max_keycode = xkb_keymap_max_keycode(keymap); + + multi_kc->keycode1 = 0; + multi_kc->keycode2 = 0; + multi_kc->keycode3 = 0; + + int found_count = 0; + + for (xkb_keycode_t keycode = min_keycode; + keycode <= max_keycode && found_count < 3; keycode++) { + // 使用布局0和层级0 + const xkb_keysym_t *syms; + int num_syms = + xkb_keymap_key_get_syms_by_level(keymap, keycode, 0, 0, &syms); + + for (int i = 0; i < num_syms; i++) { + if (syms[i] == sym) { + switch (found_count) { + case 0: + multi_kc->keycode1 = keycode; + break; + case 1: + multi_kc->keycode2 = keycode; + break; + case 2: + multi_kc->keycode3 = keycode; + break; + } + found_count++; + break; + } + } + } + + return found_count; +} + +void cleanup_config_keymap(void) { + if (config.keymap != NULL) { + xkb_keymap_unref(config.keymap); + config.keymap = NULL; + } + if (config.ctx != NULL) { + xkb_context_unref(config.ctx); + config.ctx = NULL; + } +} + +void create_config_keymap(void) { + // 初始化 xkb 上下文和 keymap + + if (config.ctx == NULL) { + config.ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS); + } + + if (config.keymap == NULL) { + config.keymap = xkb_keymap_new_from_names( + config.ctx, &xkb_fallback_rules, XKB_KEYMAP_COMPILE_NO_FLAGS); + } +} + +KeySymCode parse_key(const char *key_str, bool isbindsym) { + KeySymCode kc = {0}; // 初始化为0 + + if (config.keymap == NULL || config.ctx == NULL) { + // 处理错误 + kc.type = KEY_TYPE_SYM; + kc.keysym = XKB_KEY_NoSymbol; + return kc; + } // 处理 code: 前缀的情况 if (strncmp(key_str, "code:", 5) == 0) { char *endptr; xkb_keycode_t keycode = (xkb_keycode_t)strtol(key_str + 5, &endptr, 10); kc.type = KEY_TYPE_CODE; - kc.keycode = keycode; + kc.keycode.keycode1 = keycode; // 只设置第一个 + kc.keycode.keycode2 = 0; + kc.keycode.keycode3 = 0; return kc; } // 普通键名直接转换 xkb_keysym_t sym = xkb_keysym_from_name(key_str, XKB_KEYSYM_NO_FLAGS); - kc.type = KEY_TYPE_SYM; - kc.keycode = 0; - kc.keysym = sym; + + if (isbindsym) { + kc.type = KEY_TYPE_SYM; + kc.keysym = sym; + return kc; + } + + if (sym != XKB_KEY_NoSymbol) { + // 尝试找到对应的多个 keycode + int found_count = + find_keycodes_for_keysym(config.keymap, sym, &kc.keycode); + if (found_count > 0) { + kc.type = KEY_TYPE_CODE; + kc.keysym = sym; // 仍然保存 keysym 供参考 + } else { + kc.type = KEY_TYPE_SYM; + kc.keysym = sym; + // keycode 字段保持为0 + } + } else { + // 无法解析的键名 + kc.type = KEY_TYPE_SYM; + kc.keysym = XKB_KEY_NoSymbol; + // keycode 字段保持为0 + } + return kc; } @@ -696,7 +799,7 @@ void convert_hex_to_rgba(float *color, unsigned long int hex) { color[3] = (hex & 0xFF) / 255.0f; } -unsigned int parse_num_type(char *str) { +uint32_t parse_num_type(char *str) { switch (str[0]) { case '-': return NUM_TYPE_MINUS; @@ -740,12 +843,10 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value, func = toggleglobal; } else if (strcmp(func_name, "toggleoverview") == 0) { func = toggleoverview; + (*arg).i = atoi(arg_value); } else if (strcmp(func_name, "set_proportion") == 0) { func = set_proportion; (*arg).f = atof(arg_value); - } else if (strcmp(func_name, "increase_proportion") == 0) { - func = increase_proportion; - (*arg).f = atof(arg_value); } else if (strcmp(func_name, "switch_proportion_preset") == 0) { func = switch_proportion_preset; } else if (strcmp(func_name, "viewtoleft") == 0) { @@ -818,13 +919,13 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value, } else if (strcmp(func_name, "setkeymode") == 0) { func = setkeymode; (*arg).v = strdup(arg_value); + } else if (strcmp(func_name, "switch_keyboard_layout") == 0) { + func = switch_keyboard_layout; } else if (strcmp(func_name, "setlayout") == 0) { func = setlayout; (*arg).v = strdup(arg_value); } else if (strcmp(func_name, "switch_layout") == 0) { func = switch_layout; - } else if (strcmp(func_name, "switch_keyboard_layout") == 0) { - func = switch_keyboard_layout; } else if (strcmp(func_name, "togglefloating") == 0) { func = togglefloating; } else if (strcmp(func_name, "togglefullscreen") == 0) { @@ -850,7 +951,7 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value, } else if (strcmp(func_name, "tagmon") == 0) { func = tagmon; (*arg).i = parse_direction(arg_value); - (*arg).ui = atoi(arg_value2); + (*arg).i2 = atoi(arg_value2); if ((*arg).i == UNDIR) { (*arg).v = strdup(arg_value); }; @@ -881,8 +982,8 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value, } else if (strcmp(func_name, "moveresize") == 0) { func = moveresize; (*arg).ui = parse_mouse_action(arg_value); - } else if (strcmp(func_name, "togglemaxmizescreen") == 0) { - func = togglemaxmizescreen; + } else if (strcmp(func_name, "togglemaximizescreen") == 0) { + func = togglemaximizescreen; } else if (strcmp(func_name, "viewtoleft_have_client") == 0) { func = viewtoleft_have_client; (*arg).i = atoi(arg_value); @@ -897,8 +998,40 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value, (*arg).i = atoi(arg_value2); } else if (strcmp(func_name, "view") == 0) { func = bind_to_view; - (*arg).ui = 1 << (atoi(arg_value) - 1); + + uint32_t mask = 0; + char *token; + char *arg_copy = strdup(arg_value); + + if (arg_copy != NULL) { + char *saveptr = NULL; + token = strtok_r(arg_copy, "|", &saveptr); + + while (token != NULL) { + int num = atoi(token); + if (num > 0 && num <= LENGTH(tags)) { + mask |= (1 << (num - 1)); + } + token = strtok_r(NULL, "|", &saveptr); + } + + free(arg_copy); + } + + if (mask) { + (*arg).ui = mask; + } else { + (*arg).ui = atoi(arg_value); + } (*arg).i = atoi(arg_value2); + } else if (strcmp(func_name, "viewcrossmon") == 0) { + func = viewcrossmon; + (*arg).ui = 1 << (atoi(arg_value) - 1); + (*arg).v = strdup(arg_value2); + } else if (strcmp(func_name, "tagcrossmon") == 0) { + func = tagcrossmon; + (*arg).ui = 1 << (atoi(arg_value) - 1); + (*arg).v = strdup(arg_value2); } else if (strcmp(func_name, "toggletag") == 0) { func = toggletag; (*arg).ui = 1 << (atoi(arg_value) - 1); @@ -935,6 +1068,15 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value, (*arg).v = strdup(arg_value); (*arg).v2 = strdup(arg_value2); (*arg).v3 = strdup(arg_value3); + } else if (strcmp(func_name, "disable_monitor") == 0) { + func = disable_monitor; + (*arg).v = strdup(arg_value); + } else if (strcmp(func_name, "enable_monitor") == 0) { + func = enable_monitor; + (*arg).v = strdup(arg_value); + } else if (strcmp(func_name, "toggle_monitor") == 0) { + func = toggle_monitor; + (*arg).v = strdup(arg_value); } else { return NULL; } @@ -1010,6 +1152,8 @@ void parse_option(Config *config, char *key, char *value) { config->animation_duration_tag = atoi(value); } else if (strcmp(key, "animation_duration_close") == 0) { config->animation_duration_close = atoi(value); + } else if (strcmp(key, "animation_duration_focus") == 0) { + config->animation_duration_focus = atoi(value); } else if (strcmp(key, "animation_curve_move") == 0) { int num = parse_double_array(value, config->animation_curve_move, 4); if (num != 4) { @@ -1035,12 +1179,37 @@ void parse_option(Config *config, char *key, char *value) { "Error: Failed to parse animation_curve_close: %s\n", value); } + } else if (strcmp(key, "animation_curve_focus") == 0) { + int num = parse_double_array(value, config->animation_curve_focus, 4); + if (num != 4) { + fprintf(stderr, + "Error: Failed to parse animation_curve_focus: %s\n", + value); + } + } else if (strcmp(key, "animation_curve_opafadein") == 0) { + int num = + parse_double_array(value, config->animation_curve_opafadein, 4); + if (num != 4) { + fprintf(stderr, + "Error: Failed to parse animation_curve_opafadein: %s\n", + value); + } + } else if (strcmp(key, "animation_curve_opafadeout") == 0) { + int num = + parse_double_array(value, config->animation_curve_opafadeout, 4); + if (num != 4) { + fprintf(stderr, + "Error: Failed to parse animation_curve_opafadeout: %s\n", + value); + } } else if (strcmp(key, "scroller_structs") == 0) { config->scroller_structs = atoi(value); } else if (strcmp(key, "scroller_default_proportion") == 0) { config->scroller_default_proportion = atof(value); } else if (strcmp(key, "scroller_default_proportion_single") == 0) { config->scroller_default_proportion_single = atof(value); + } else if (strcmp(key, "scroller_ignore_proportion_single") == 0) { + config->scroller_ignore_proportion_single = atoi(value); } else if (strcmp(key, "scroller_focus_center") == 0) { config->scroller_focus_center = atoi(value); } else if (strcmp(key, "scroller_prefer_center") == 0) { @@ -1099,6 +1268,12 @@ void parse_option(Config *config, char *key, char *value) { config->syncobj_enable = atoi(value); } else if (strcmp(key, "adaptive_sync") == 0) { config->adaptive_sync = atoi(value); + } else if (strcmp(key, "allow_tearing") == 0) { + config->allow_tearing = atoi(value); + } else if (strcmp(key, "allow_shortcuts_inhibit") == 0) { + config->allow_shortcuts_inhibit = atoi(value); + } else if (strcmp(key, "allow_lock_transparent") == 0) { + config->allow_lock_transparent = atoi(value); } else if (strcmp(key, "no_border_when_single") == 0) { config->no_border_when_single = atoi(value); } else if (strcmp(key, "no_radius_when_single") == 0) { @@ -1284,8 +1459,8 @@ void parse_option(Config *config, char *key, char *value) { config->focus_on_activate = atoi(value); } else if (strcmp(key, "numlockon") == 0) { config->numlockon = atoi(value); - } else if (strcmp(key, "inhibit_regardless_of_visibility") == 0) { - config->inhibit_regardless_of_visibility = atoi(value); + } else if (strcmp(key, "idleinhibit_ignore_visible") == 0) { + config->idleinhibit_ignore_visible = atoi(value); } else if (strcmp(key, "sloppyfocus") == 0) { config->sloppyfocus = atoi(value); } else if (strcmp(key, "warpcursor") == 0) { @@ -1332,6 +1507,8 @@ void parse_option(Config *config, char *key, char *value) { config->send_events_mode = atoi(value); } else if (strcmp(key, "button_map") == 0) { config->button_map = atoi(value); + } else if (strcmp(key, "axis_scroll_factor") == 0) { + config->axis_scroll_factor = atof(value); } else if (strcmp(key, "gappih") == 0) { config->gappih = atoi(value); } else if (strcmp(key, "gappiv") == 0) { @@ -1375,13 +1552,13 @@ void parse_option(Config *config, char *key, char *value) { } else { convert_hex_to_rgba(config->focuscolor, color); } - } else if (strcmp(key, "maxmizescreencolor") == 0) { + } else if (strcmp(key, "maximizescreencolor") == 0) { long int color = parse_color(value); if (color == -1) { - fprintf(stderr, "Error: Invalid maxmizescreencolor format: %s\n", + fprintf(stderr, "Error: Invalid maximizescreencolor format: %s\n", value); } else { - convert_hex_to_rgba(config->maxmizescreencolor, color); + convert_hex_to_rgba(config->maximizescreencolor, color); } } else if (strcmp(key, "urgentcolor") == 0) { long int color = parse_color(value); @@ -1528,20 +1705,26 @@ void parse_option(Config *config, char *key, char *value) { rule->isfloating = -1; rule->isfullscreen = -1; rule->isnoborder = -1; + rule->isnoshadow = -1; + rule->isnoradius = -1; + rule->isnoanimation = -1; rule->isopensilent = -1; rule->istagsilent = -1; rule->isnamedscratchpad = -1; rule->isunglobal = -1; rule->isglobal = -1; rule->isoverlay = -1; + rule->allow_shortcuts_inhibit = -1; rule->ignore_maximize = -1; rule->ignore_minimize = -1; rule->isnosizehint = -1; rule->isterm = -1; rule->allow_csd = -1; rule->force_maximize = -1; + rule->force_tearing = -1; rule->noswallow = -1; rule->noblur = -1; + rule->nofocus = -1; rule->nofadein = -1; rule->nofadeout = -1; rule->no_force_center = -1; @@ -1553,6 +1736,7 @@ void parse_option(Config *config, char *key, char *value) { // float rule value, relay to a client property rule->focused_opacity = 0; rule->unfocused_opacity = 0; + rule->scroller_proportion_single = 0.0f; rule->scroller_proportion = 0; // special rule value,not directly set to client property @@ -1596,6 +1780,8 @@ void parse_option(Config *config, char *key, char *value) { rule->offsetx = atoi(val); } else if (strcmp(key, "offsety") == 0) { rule->offsety = atoi(val); + } else if (strcmp(key, "nofocus") == 0) { + rule->nofocus = atoi(val); } else if (strcmp(key, "nofadein") == 0) { rule->nofadein = atoi(val); } else if (strcmp(key, "nofadeout") == 0) { @@ -1608,6 +1794,12 @@ void parse_option(Config *config, char *key, char *value) { rule->height = atoi(val); } else if (strcmp(key, "isnoborder") == 0) { rule->isnoborder = atoi(val); + } else if (strcmp(key, "isnoshadow") == 0) { + rule->isnoshadow = atoi(val); + } else if (strcmp(key, "isnoradius") == 0) { + rule->isnoradius = atoi(val); + } else if (strcmp(key, "isnoanimation") == 0) { + rule->isnoanimation = atoi(val); } else if (strcmp(key, "isopensilent") == 0) { rule->isopensilent = atoi(val); } else if (strcmp(key, "istagsilent") == 0) { @@ -1618,12 +1810,16 @@ void parse_option(Config *config, char *key, char *value) { rule->isunglobal = atoi(val); } else if (strcmp(key, "isglobal") == 0) { rule->isglobal = atoi(val); + } else if (strcmp(key, "scroller_proportion_single") == 0) { + rule->scroller_proportion_single = atof(val); } else if (strcmp(key, "unfocused_opacity") == 0) { rule->unfocused_opacity = atof(val); } else if (strcmp(key, "focused_opacity") == 0) { rule->focused_opacity = atof(val); } else if (strcmp(key, "isoverlay") == 0) { rule->isoverlay = atoi(val); + } else if (strcmp(key, "allow_shortcuts_inhibit") == 0) { + rule->allow_shortcuts_inhibit = atoi(val); } else if (strcmp(key, "ignore_maximize") == 0) { rule->ignore_maximize = atoi(val); } else if (strcmp(key, "ignore_minimize") == 0) { @@ -1636,6 +1832,8 @@ void parse_option(Config *config, char *key, char *value) { rule->allow_csd = atoi(val); } else if (strcmp(key, "force_maximize") == 0) { rule->force_maximize = atoi(val); + } else if (strcmp(key, "force_tearing") == 0) { + rule->force_tearing = atoi(val); } else if (strcmp(key, "noswallow") == 0) { rule->noswallow = atoi(val); } else if (strcmp(key, "noblur") == 0) { @@ -1650,7 +1848,8 @@ void parse_option(Config *config, char *key, char *value) { trim_whitespace(mod_str); trim_whitespace(keysym_str); rule->globalkeybinding.mod = parse_mod(mod_str); - rule->globalkeybinding.keysymcode = parse_key(keysym_str); + rule->globalkeybinding.keysymcode = + parse_key(keysym_str, false); } } token = strtok(NULL, ","); @@ -1787,7 +1986,7 @@ void parse_option(Config *config, char *key, char *value) { config->exec_once_count++; - } else if (strncmp(key, "bind", 4) == 0) { + } else if (regex_match("^bind[s|l|r|p]*$", key)) { config->key_bindings = realloc(config->key_bindings, (config->key_bindings_count + 1) * sizeof(KeyBinding)); @@ -1833,8 +2032,10 @@ void parse_option(Config *config, char *key, char *value) { binding->iscommonmode = false; } + parse_bind_flags(key, binding); + binding->keysymcode = + parse_key(keysym_str, binding->keysymcode.type == KEY_TYPE_SYM); binding->mod = parse_mod(mod_str); - binding->keysymcode = parse_key(keysym_str); binding->arg.v = NULL; binding->arg.v2 = NULL; binding->arg.v3 = NULL; @@ -2131,35 +2332,55 @@ void parse_config_line(Config *config, const char *line) { void parse_config_file(Config *config, const char *file_path) { FILE *file; - // 检查路径是否以 ~/ 开头 - if (file_path[0] == '~' && (file_path[1] == '/' || file_path[1] == '\0')) { + char full_path[1024]; + + if (file_path[0] == '.' && file_path[1] == '/') { + // Relative path + + if (cli_config_path) { + char *config_path = strdup(cli_config_path); + char *config_dir = dirname(config_path); + snprintf(full_path, sizeof(full_path), "%s/%s", config_dir, + file_path + 1); + free(config_path); + } else { + const char *home = getenv("HOME"); + if (!home) { + fprintf(stderr, "Error: HOME environment variable not set.\n"); + return; + } + snprintf(full_path, sizeof(full_path), "%s/.config/mango/%s", home, + file_path + 1); + } + file = fopen(full_path, "r"); + + } else if (file_path[0] == '~' && + (file_path[1] == '/' || file_path[1] == '\0')) { + // Home directory + const char *home = getenv("HOME"); if (!home) { fprintf(stderr, "Error: HOME environment variable not set.\n"); return; } - - // 构建完整路径(家目录 + / + 原路径去掉 ~) - char full_path[1024]; snprintf(full_path, sizeof(full_path), "%s%s", home, file_path + 1); - file = fopen(full_path, "r"); - if (!file) { - perror("Error opening file"); - return; - } + } else { + // Absolute path file = fopen(file_path, "r"); - if (!file) { - perror("Error opening file"); - return; - } + } + + if (!file) { + perror("Error opening file"); + return; } char line[512]; while (fgets(line, sizeof(line), file)) { - if (line[0] == '#' || line[0] == '\n') + if (line[0] == '#' || line[0] == '\n') { continue; + } parse_config_line(config, line); } @@ -2199,6 +2420,18 @@ void free_baked_points(void) { free(baked_points_tag); baked_points_tag = NULL; } + if (baked_points_focus) { + free(baked_points_focus); + baked_points_focus = NULL; + } + if (baked_points_opafadein) { + free(baked_points_opafadein); + baked_points_opafadein = NULL; + } + if (baked_points_opafadeout) { + free(baked_points_opafadeout); + baked_points_opafadeout = NULL; + } } void free_config(void) { @@ -2432,6 +2665,9 @@ void free_config(void) { // 释放动画资源 free_baked_points(); + + // 清理解析按键用的keymap + cleanup_config_keymap(); } void override_config(void) { @@ -2467,12 +2703,16 @@ void override_config(void) { animation_duration_tag = CLAMP_INT(config.animation_duration_tag, 1, 50000); animation_duration_close = CLAMP_INT(config.animation_duration_close, 1, 50000); + animation_duration_focus = + CLAMP_INT(config.animation_duration_focus, 1, 50000); // 滚动布局设置 scroller_default_proportion = CLAMP_FLOAT(config.scroller_default_proportion, 0.1f, 1.0f); scroller_default_proportion_single = CLAMP_FLOAT(config.scroller_default_proportion_single, 0.1f, 1.0f); + scroller_ignore_proportion_single = + CLAMP_INT(config.scroller_ignore_proportion_single, 0, 1); scroller_focus_center = CLAMP_INT(config.scroller_focus_center, 0, 1); scroller_prefer_center = CLAMP_INT(config.scroller_prefer_center, 0, 1); edge_scroller_pointer_focus = @@ -2497,11 +2737,14 @@ void override_config(void) { xwayland_persistence = CLAMP_INT(config.xwayland_persistence, 0, 1); syncobj_enable = CLAMP_INT(config.syncobj_enable, 0, 1); adaptive_sync = CLAMP_INT(config.adaptive_sync, 0, 1); + allow_tearing = CLAMP_INT(config.allow_tearing, 0, 2); + allow_shortcuts_inhibit = CLAMP_INT(config.allow_shortcuts_inhibit, 0, 1); + allow_lock_transparent = CLAMP_INT(config.allow_lock_transparent, 0, 1); axis_bind_apply_timeout = CLAMP_INT(config.axis_bind_apply_timeout, 0, 1000); focus_on_activate = CLAMP_INT(config.focus_on_activate, 0, 1); - inhibit_regardless_of_visibility = - CLAMP_INT(config.inhibit_regardless_of_visibility, 0, 1); + idleinhibit_ignore_visible = + CLAMP_INT(config.idleinhibit_ignore_visible, 0, 1); sloppyfocus = CLAMP_INT(config.sloppyfocus, 0, 1); warpcursor = CLAMP_INT(config.warpcursor, 0, 1); focus_cross_monitor = CLAMP_INT(config.focus_cross_monitor, 0, 1); @@ -2545,6 +2788,7 @@ void override_config(void) { click_method = CLAMP_INT(config.click_method, 0, 2); send_events_mode = CLAMP_INT(config.send_events_mode, 0, 2); button_map = CLAMP_INT(config.button_map, 0, 1); + axis_scroll_factor = CLAMP_FLOAT(config.axis_scroll_factor, 0.1f, 10.0f); // 外观设置 gappih = CLAMP_INT(config.gappih, 0, 1000); @@ -2583,8 +2827,8 @@ void override_config(void) { memcpy(rootcolor, config.rootcolor, sizeof(rootcolor)); memcpy(bordercolor, config.bordercolor, sizeof(bordercolor)); memcpy(focuscolor, config.focuscolor, sizeof(focuscolor)); - memcpy(maxmizescreencolor, config.maxmizescreencolor, - sizeof(maxmizescreencolor)); + memcpy(maximizescreencolor, config.maximizescreencolor, + sizeof(maximizescreencolor)); memcpy(urgentcolor, config.urgentcolor, sizeof(urgentcolor)); memcpy(scratchpadcolor, config.scratchpadcolor, sizeof(scratchpadcolor)); memcpy(globalcolor, config.globalcolor, sizeof(globalcolor)); @@ -2599,6 +2843,12 @@ void override_config(void) { sizeof(animation_curve_tag)); memcpy(animation_curve_close, config.animation_curve_close, sizeof(animation_curve_close)); + memcpy(animation_curve_focus, config.animation_curve_focus, + sizeof(animation_curve_focus)); + memcpy(animation_curve_opafadein, config.animation_curve_opafadein, + sizeof(animation_curve_opafadein)); + memcpy(animation_curve_opafadeout, config.animation_curve_opafadeout, + sizeof(animation_curve_opafadeout)); } void set_value_default() { @@ -2621,6 +2871,8 @@ void set_value_default() { animation_duration_tag; // Animation tag speed config.animation_duration_close = animation_duration_close; // Animation tag speed + config.animation_duration_focus = + animation_duration_focus; // Animation focus opacity speed /* appearance */ config.axis_bind_apply_timeout = @@ -2655,6 +2907,8 @@ void set_value_default() { config.scroller_default_proportion = scroller_default_proportion; config.scroller_default_proportion_single = scroller_default_proportion_single; + config.scroller_ignore_proportion_single = + scroller_ignore_proportion_single; config.scroller_focus_center = scroller_focus_center; config.scroller_prefer_center = scroller_prefer_center; config.edge_scroller_pointer_focus = edge_scroller_pointer_focus; @@ -2662,11 +2916,15 @@ void set_value_default() { config.exchange_cross_monitor = exchange_cross_monitor; config.scratchpad_cross_monitor = scratchpad_cross_monitor; config.focus_cross_tag = focus_cross_tag; + config.axis_scroll_factor = axis_scroll_factor; config.view_current_to_back = view_current_to_back; config.single_scratchpad = single_scratchpad; config.xwayland_persistence = xwayland_persistence; config.syncobj_enable = syncobj_enable; config.adaptive_sync = adaptive_sync; + config.allow_tearing = allow_tearing; + config.allow_shortcuts_inhibit = allow_shortcuts_inhibit; + config.allow_lock_transparent = allow_lock_transparent; config.no_border_when_single = no_border_when_single; config.no_radius_when_single = no_radius_when_single; config.snap_distance = snap_distance; @@ -2674,8 +2932,8 @@ void set_value_default() { config.enable_floating_snap = enable_floating_snap; config.swipe_min_threshold = swipe_min_threshold; - config.inhibit_regardless_of_visibility = - inhibit_regardless_of_visibility; /* 1 means idle inhibitors will + config.idleinhibit_ignore_visible = + idleinhibit_ignore_visible; /* 1 means idle inhibitors will disable idle tracking even if it's surface isn't visible */ @@ -2738,12 +2996,18 @@ void set_value_default() { sizeof(animation_curve_tag)); memcpy(config.animation_curve_close, animation_curve_close, sizeof(animation_curve_close)); + memcpy(config.animation_curve_focus, animation_curve_focus, + sizeof(animation_curve_focus)); + memcpy(config.animation_curve_opafadein, animation_curve_opafadein, + sizeof(animation_curve_opafadein)); + memcpy(config.animation_curve_opafadeout, animation_curve_opafadeout, + sizeof(animation_curve_opafadeout)); memcpy(config.rootcolor, rootcolor, sizeof(rootcolor)); memcpy(config.bordercolor, bordercolor, sizeof(bordercolor)); memcpy(config.focuscolor, focuscolor, sizeof(focuscolor)); - memcpy(config.maxmizescreencolor, maxmizescreencolor, - sizeof(maxmizescreencolor)); + memcpy(config.maximizescreencolor, maximizescreencolor, + sizeof(maximizescreencolor)); memcpy(config.urgentcolor, urgentcolor, sizeof(urgentcolor)); memcpy(config.scratchpadcolor, scratchpadcolor, sizeof(scratchpadcolor)); memcpy(config.globalcolor, globalcolor, sizeof(globalcolor)); @@ -2770,6 +3034,7 @@ void set_default_key_bindings(Config *config) { default_key_bindings[i]; config->key_bindings[config->key_bindings_count + i].iscommonmode = true; + config->key_bindings[config->key_bindings_count + i].islockapply = true; } // 更新按键绑定的总数 @@ -2784,6 +3049,11 @@ void parse_config(void) { // 重置config结构体,确保所有指针初始化为NULL memset(&config, 0, sizeof(config)); + memset(&xkb_rules_rules, 0, sizeof(xkb_rules_rules)); + memset(&xkb_rules_model, 0, sizeof(xkb_rules_model)); + memset(&xkb_rules_layout, 0, sizeof(xkb_rules_layout)); + memset(&xkb_rules_variant, 0, sizeof(xkb_rules_variant)); + memset(&xkb_rules_options, 0, sizeof(xkb_rules_options)); // 初始化动态数组的指针为NULL,避免野指针 config.window_rules = NULL; @@ -2815,11 +3085,11 @@ void parse_config(void) { config.cursor_theme = NULL; strcpy(config.keymode, "default"); - // 获取 MANGOCONFIG 环境变量 - const char *mangoconfig = getenv("MANGOCONFIG"); + create_config_keymap(); - // 如果 MANGOCONFIG 环境变量不存在或为空,则使用 HOME 环境变量 - if (!mangoconfig || mangoconfig[0] == '\0') { + if (cli_config_path) { + snprintf(filename, sizeof(filename), "%s", cli_config_path); + } else { // 获取当前用户家目录 const char *homedir = getenv("HOME"); if (!homedir) { @@ -2836,9 +3106,6 @@ void parse_config(void) { snprintf(filename, sizeof(filename), "%s/mango/config.conf", SYSCONFDIR); } - } else { - // 使用 MANGOCONFIG 环境变量作为配置文件夹路径 - snprintf(filename, sizeof(filename), "%s/config.conf", mangoconfig); } set_value_default(); @@ -2936,13 +3203,47 @@ void reapply_monitor_rules(void) { } } +void reapply_cursor_style(void) { + if (hide_source) { + wl_event_source_timer_update(hide_source, 0); + wl_event_source_remove(hide_source); + hide_source = NULL; + } + + wlr_cursor_unset_image(cursor); + + wlr_cursor_set_surface(cursor, NULL, 0, 0); + + if (cursor_mgr) { + wlr_xcursor_manager_destroy(cursor_mgr); + cursor_mgr = NULL; + } + + cursor_mgr = wlr_xcursor_manager_create(config.cursor_theme, cursor_size); + + Monitor *m = NULL; + wl_list_for_each(m, &mons, link) { + wlr_xcursor_manager_load(cursor_mgr, m->wlr_output->scale); + } + + wlr_cursor_set_xcursor(cursor, cursor_mgr, "left_ptr"); + + hide_source = wl_event_loop_add_timer(wl_display_get_event_loop(dpy), + hidecursor, cursor); + if (cursor_hidden) { + wlr_cursor_unset_image(cursor); + } else { + wl_event_source_timer_update(hide_source, cursor_hide_timeout * 1000); + } +} + void reapply_border(void) { Client *c = NULL; // reset border width when config change wl_list_for_each(c, &clients, link) { if (c && !c->iskilling) { - if (!c->isnoborder) { + if (!c->isnoborder && !c->isfullscreen) { c->bw = borderpx; } } @@ -2995,33 +3296,37 @@ void reapply_master(void) { } } +void parse_tagrule(Monitor *m) { + int i, jk; + ConfigTagRule tr; + + for (i = 0; i < config.tag_rules_count; i++) { + + tr = config.tag_rules[i]; + + if (config.tag_rules_count > 0 && + (!tr.monitor_name || + regex_match(tr.monitor_name, m->wlr_output->name))) { + + for (jk = 0; jk < LENGTH(layouts); jk++) { + if (tr.layout_name && + strcmp(layouts[jk].name, tr.layout_name) == 0) { + m->pertag->ltidxs[tr.id] = &layouts[jk]; + } + } + + m->pertag->no_hide[tr.id] = tr.no_hide; + } + } +} + void reapply_tagrule(void) { Monitor *m = NULL; - int i, jk; - char *rule_monitor_name = NULL; wl_list_for_each(m, &mons, link) { if (!m->wlr_output->enabled) { continue; } - - // apply tag rule - for (i = 1; i <= config.tag_rules_count; i++) { - rule_monitor_name = config.tag_rules[i - 1].monitor_name; - if (regex_match(rule_monitor_name, m->wlr_output->name) || - !rule_monitor_name) { - for (jk = 0; jk < LENGTH(layouts); jk++) { - if (config.tag_rules_count > 0 && - config.tag_rules[i - 1].layout_name && - strcmp(layouts[jk].name, - config.tag_rules[i - 1].layout_name) == 0) { - m->pertag->ltidxs[config.tag_rules[i - 1].id] = - &layouts[jk]; - m->pertag->no_hide[config.tag_rules[i - 1].id] = - config.tag_rules[i - 1].no_hide; - } - } - } - } + parse_tagrule(m); } } @@ -3033,6 +3338,7 @@ void reset_option(void) { set_env(); run_exec(); + reapply_cursor_style(); reapply_border(); reapply_keyboard(); reapply_pointer(); @@ -3047,5 +3353,6 @@ void reset_option(void) { int reload_config(const Arg *arg) { parse_config(); reset_option(); - return 0; + printstatus(); + return 1; } diff --git a/src/config/preset.h b/src/config/preset.h index 31956cf9..31f514f8 100644 --- a/src/config/preset.h +++ b/src/config/preset.h @@ -25,39 +25,44 @@ uint32_t animation_duration_move = 500; // Animation move speed uint32_t animation_duration_open = 400; // Animation open speed uint32_t animation_duration_tag = 300; // Animation tag speed uint32_t animation_duration_close = 300; // Animation close speed -double animation_curve_move[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 -double animation_curve_open[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 -double animation_curve_tag[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 -double animation_curve_close[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 +uint32_t animation_duration_focus = 0; // Animation focus opacity speed +double animation_curve_move[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 +double animation_curve_open[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 +double animation_curve_tag[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 +double animation_curve_close[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 +double animation_curve_focus[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 +double animation_curve_opafadein[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 +double animation_curve_opafadeout[4] = {0.5, 0.5, 0.5, 0.5}; // 动画曲线 /* appearance */ -unsigned int axis_bind_apply_timeout = 100; // 滚轮绑定动作的触发的时间间隔 -unsigned int focus_on_activate = 1; // 收到窗口激活请求是否自动跳转聚焦 -unsigned int new_is_master = 1; // 新窗口是否插在头部 -double default_mfact = 0.55f; // master 窗口比例 -unsigned int default_nmaster = 1; // 默认master数量 -int center_master_overspread = 0; // 中心master时是否铺满 -int center_when_single_stack = 1; // 单个stack时是否居中 +uint32_t axis_bind_apply_timeout = 100; // 滚轮绑定动作的触发的时间间隔 +uint32_t focus_on_activate = 1; // 收到窗口激活请求是否自动跳转聚焦 +uint32_t new_is_master = 1; // 新窗口是否插在头部 +double default_mfact = 0.55f; // master 窗口比例 +uint32_t default_nmaster = 1; // 默认master数量 +int center_master_overspread = 0; // 中心master时是否铺满 +int center_when_single_stack = 1; // 单个stack时是否居中 /* logging */ int log_level = WLR_ERROR; -unsigned int numlockon = 1; // 是否打开右边小键盘 -unsigned int capslock = 0; // 是否启用快捷键 +uint32_t numlockon = 0; // 是否打开右边小键盘 +uint32_t capslock = 0; // 是否启用快捷键 -unsigned int ov_tab_mode = 0; // alt tab切换模式 -unsigned int hotarea_size = 10; // 热区大小,10x10 -unsigned int enable_hotarea = 1; // 是否启用鼠标热区 -int smartgaps = 0; /* 1 means no outer gap when there is only one window */ -int sloppyfocus = 1; /* focus follows mouse */ -unsigned int gappih = 5; /* horiz inner gap between windows */ -unsigned int gappiv = 5; /* vert inner gap between windows */ -unsigned int gappoh = 10; /* horiz outer gap between windows and screen edge */ -unsigned int gappov = 10; /* vert outer gap between windows and screen edge */ +uint32_t ov_tab_mode = 0; // alt tab切换模式 +uint32_t hotarea_size = 10; // 热区大小,10x10 +uint32_t enable_hotarea = 1; // 是否启用鼠标热区 +int smartgaps = 0; /* 1 means no outer gap when there is only one window */ +int sloppyfocus = 1; /* focus follows mouse */ +uint32_t gappih = 5; /* horiz inner gap between windows */ +uint32_t gappiv = 5; /* vert inner gap between windows */ +uint32_t gappoh = 10; /* horiz outer gap between windows and screen edge */ +uint32_t gappov = 10; /* vert outer gap between windows and screen edge */ float scratchpad_width_ratio = 0.8; float scratchpad_height_ratio = 0.9; int scroller_structs = 20; float scroller_default_proportion = 0.9; float scroller_default_proportion_single = 1.0; +int scroller_ignore_proportion_single = 0; int scroller_focus_center = 0; int scroller_prefer_center = 0; int focus_cross_monitor = 0; @@ -70,19 +75,19 @@ int no_radius_when_single = 0; int snap_distance = 30; int enable_floating_snap = 0; int drag_tile_to_tile = 0; -unsigned int cursor_size = 24; -unsigned int cursor_hide_timeout = 0; +uint32_t cursor_size = 24; +uint32_t cursor_hide_timeout = 0; -unsigned int swipe_min_threshold = 1; +uint32_t swipe_min_threshold = 1; -int inhibit_regardless_of_visibility = +int idleinhibit_ignore_visible = 0; /* 1 means idle inhibitors will disable idle tracking even if it's surface isn't visible */ -unsigned int borderpx = 4; /* border pixel of windows */ +uint32_t borderpx = 4; /* border pixel of windows */ float rootcolor[] = COLOR(0x323232ff); float bordercolor[] = COLOR(0x444444ff); float focuscolor[] = COLOR(0xc66b25ff); -float maxmizescreencolor[] = COLOR(0x89aa61ff); +float maximizescreencolor[] = COLOR(0x89aa61ff); float urgentcolor[] = COLOR(0xad401fff); float scratchpadcolor[] = COLOR(0x516c93ff); float globalcolor[] = COLOR(0xb153a7ff); @@ -100,7 +105,10 @@ int warpcursor = 1; /* Warp cursor to focused client */ int xwayland_persistence = 1; /* xwayland persistence */ int syncobj_enable = 0; int adaptive_sync = 0; -double drag_refresh_interval = 30.0; +int allow_lock_transparent = 0; +double drag_refresh_interval = 16.0; +int allow_tearing = TEARING_DISABLED; +int allow_shortcuts_inhibit = SHORTCUTS_INHIBIT_ENABLE; /* keyboard */ @@ -114,6 +122,19 @@ char xkb_rules_layout[256]; char xkb_rules_variant[256]; char xkb_rules_options[256]; +/* keyboard */ +static const struct xkb_rule_names xkb_fallback_rules = { + .layout = "us", + .variant = NULL, + .model = NULL, + .rules = NULL, + .options = NULL, +}; + +static const struct xkb_rule_names xkb_default_rules = { + .options = NULL, +}; + struct xkb_rule_names xkb_rules = { /* can specify fields: rules, model, layout, variant, options */ /* example: @@ -147,7 +168,7 @@ LIBINPUT_CONFIG_SCROLL_EDGE LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN */ enum libinput_config_scroll_method scroll_method = LIBINPUT_CONFIG_SCROLL_2FG; -unsigned int scroll_button = 274; +uint32_t scroll_button = 274; /* You can choose between: LIBINPUT_CONFIG_CLICK_METHOD_NONE @@ -157,6 +178,8 @@ LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER enum libinput_config_click_method click_method = LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS; +double axis_scroll_factor = 1.0; + /* You can choose between: LIBINPUT_CONFIG_SEND_EVENTS_ENABLED LIBINPUT_CONFIG_SEND_EVENTS_DISABLED @@ -205,7 +228,7 @@ float blur_params_saturation = 1.2; int shadows = 0; int shadow_only_floating = 1; int layer_shadows = 0; -unsigned int shadows_size = 10; +uint32_t shadows_size = 10; double shadows_blur = 15; int shadows_position_x = 0; int shadows_position_y = 0; diff --git a/src/dispatch/bind_declare.h b/src/dispatch/bind_declare.h index cc84923c..5bc215a2 100644 --- a/src/dispatch/bind_declare.h +++ b/src/dispatch/bind_declare.h @@ -4,28 +4,29 @@ int toggle_scratchpad(const Arg *arg); int focusdir(const Arg *arg); int toggleoverview(const Arg *arg); int set_proportion(const Arg *arg); -int increase_proportion(const Arg *arg); int switch_proportion_preset(const Arg *arg); int zoom(const Arg *arg); int tagsilent(const Arg *arg); int tagtoleft(const Arg *arg); int tagtoright(const Arg *arg); +int tagcrossmon(const Arg *arg); int viewtoleft(const Arg *arg); int viewtoright(const Arg *arg); int viewtoleft_have_client(const Arg *arg); int viewtoright_have_client(const Arg *arg); +int viewcrossmon(const Arg *arg); int togglefloating(const Arg *arg); int togglefullscreen(const Arg *arg); -int togglemaxmizescreen(const Arg *arg); +int togglemaximizescreen(const Arg *arg); int togglegaps(const Arg *arg); int tagmon(const Arg *arg); int spawn(const Arg *arg); int spawn_shell(const Arg *arg); int spawn_on_empty(const Arg *arg); int setkeymode(const Arg *arg); +int switch_keyboard_layout(const Arg *arg); int setlayout(const Arg *arg); int switch_layout(const Arg *arg); -int switch_keyboard_layout(const Arg *arg); int setmfact(const Arg *arg); int quit(const Arg *arg); int moveresize(const Arg *arg); @@ -64,4 +65,7 @@ int create_virtual_output(const Arg *arg); int destroy_all_virtual_output(const Arg *arg); int focuslast(const Arg *arg); int toggle_trackpad_enable(const Arg *arg); -int setoption(const Arg *arg); \ No newline at end of file +int setoption(const Arg *arg); +int disable_monitor(const Arg *arg); +int enable_monitor(const Arg *arg); +int toggle_monitor(const Arg *arg); \ No newline at end of file diff --git a/src/dispatch/bind_define.h b/src/dispatch/bind_define.h index 93de6d7f..6544cab8 100644 --- a/src/dispatch/bind_define.h +++ b/src/dispatch/bind_define.h @@ -1,6 +1,6 @@ int bind_to_view(const Arg *arg) { - unsigned int target = arg->ui; + uint32_t target = arg->ui; if (view_current_to_back && selmon->pertag->curtag && (target & TAGMASK) == (selmon->tagset[selmon->seltags])) { @@ -80,8 +80,12 @@ int defaultgaps(const Arg *arg) { int exchange_client(const Arg *arg) { Client *c = selmon->sel; - if (!c || c->isfloating || c->isfullscreen || c->ismaxmizescreen) + if (!c || c->isfloating) return 0; + + if ((c->isfullscreen || c->ismaximizescreen) && !is_scroller_layout(c->mon)) + return 0; + exchange_two_client(c, direction_select(arg)); return 0; } @@ -89,7 +93,7 @@ int exchange_client(const Arg *arg) { int exchange_stack_client(const Arg *arg) { Client *c = selmon->sel; Client *tc = NULL; - if (!c || c->isfloating || c->isfullscreen || c->ismaxmizescreen) + if (!c || c->isfloating || c->isfullscreen || c->ismaximizescreen) return 0; if (arg->i == NEXT) { tc = get_next_stack_client(c, false); @@ -126,12 +130,12 @@ int focuslast(const Arg *arg) { Client *c = NULL; Client *tc = NULL; bool begin = false; - unsigned int target = 0; + uint32_t target = 0; wl_list_for_each(c, &fstack, flink) { - if (c->iskilling || c->isminied || c->isunglobal || + if (c->iskilling || c->isminimized || c->isunglobal || !client_surface(c)->mapped || client_is_unmanaged(c) || - client_should_ignore_focus(c)) + client_is_x11_popup(c)) continue; if (selmon && !selmon->sel) { @@ -167,17 +171,19 @@ int toggle_trackpad_enable(const Arg *arg) { } int focusmon(const Arg *arg) { - Client *c = NULL, *old_selmon_sel = NULL; + Client *c = NULL; Monitor *m = NULL; + Monitor *tm = NULL; if (arg->i != UNDIR) { - m = dirtomon(arg->i); + tm = dirtomon(arg->i); } else if (arg->v) { wl_list_for_each(m, &mons, link) { if (!m->wlr_output->enabled) { continue; } if (regex_match(arg->v, m->wlr_output->name)) { + tm = m; break; } } @@ -185,11 +191,10 @@ int focusmon(const Arg *arg) { return 0; } - if (!m || !m->wlr_output->enabled) + if (!tm || !tm->wlr_output->enabled || tm == selmon) return 0; - old_selmon_sel = selmon->sel; - selmon = m; + selmon = tm; if (warpcursor) { warp_cursor_to_selmon(selmon); } @@ -198,12 +203,10 @@ int focusmon(const Arg *arg) { selmon->sel = NULL; wlr_seat_pointer_notify_clear_focus(seat); wlr_seat_keyboard_notify_clear_focus(seat); + focusclient(NULL, 0); } else focusclient(c, 1); - if (old_selmon_sel) { - setborder_color(old_selmon_sel); - } return 0; } @@ -212,7 +215,7 @@ int focusstack(const Arg *arg) { Client *sel = focustop(selmon); Client *tc = NULL; - if (!sel || (sel->isfullscreen && !client_has_children(sel))) + if (!sel) return 0; if (arg->i == NEXT) { tc = get_next_stack_client(sel, false); @@ -281,18 +284,6 @@ int incovgaps(const Arg *arg) { return 0; } -int increase_proportion(const Arg *arg) { - if (selmon->sel) { - unsigned int max_client_width = - selmon->w.width - 2 * scroller_structs - gappih; - selmon->sel->scroller_proportion = - MIN(MAX(arg->f + selmon->sel->scroller_proportion, 0.1), 1.0); - selmon->sel->geom.width = max_client_width * arg->f; - arrange(selmon, false); - } - return 0; -} - int setmfact(const Arg *arg) { float f; Client *c = NULL; @@ -329,7 +320,7 @@ int moveresize(const Arg *arg) { return 0; xytonode(cursor->x, cursor->y, NULL, &grabc, NULL, NULL, NULL); if (!grabc || client_is_unmanaged(grabc) || grabc->isfullscreen || - grabc->ismaxmizescreen) { + grabc->ismaximizescreen) { grabc = NULL; return 0; } @@ -410,7 +401,7 @@ int resizewin(const Arg *arg) { c = selmon->sel; int offsetx = 0, offsety = 0; - if (!c || c->isfullscreen || c->ismaxmizescreen) + if (!c || c->isfullscreen || c->ismaximizescreen) return 0; if (ISTILED(c)) { @@ -479,7 +470,7 @@ int restore_minimized(const Arg *arg) { if (selmon && selmon->sel && selmon->sel->is_in_scratchpad && selmon->sel->is_scratchpad_show) { - selmon->sel->isminied = 0; + selmon->sel->isminimized = 0; selmon->sel->is_scratchpad_show = 0; selmon->sel->is_in_scratchpad = 0; selmon->sel->isnamedscratchpad = 0; @@ -488,7 +479,7 @@ int restore_minimized(const Arg *arg) { } wl_list_for_each(c, &clients, link) { - if (c->isminied) { + if (c->isminimized && !c->isnamedscratchpad) { c->is_scratchpad_show = 0; c->is_in_scratchpad = 0; c->isnamedscratchpad = 0; @@ -509,7 +500,7 @@ int setlayout(const Arg *arg) { for (jk = 0; jk < LENGTH(layouts); jk++) { if (strcmp(layouts[jk].name, arg->v) == 0) { selmon->pertag->ltidxs[selmon->pertag->curtag] = &layouts[jk]; - + clear_fullscreen_and_maximized_state(selmon); arrange(selmon, false); printstatus(); return 0; @@ -530,8 +521,16 @@ int setkeymode(const Arg *arg) { } int set_proportion(const Arg *arg) { + + if (selmon->isoverview || !is_scroller_layout(selmon)) + return 0; + + if (selmon->visible_tiling_clients == 1 && + !scroller_ignore_proportion_single) + return 0; + if (selmon->sel) { - unsigned int max_client_width = + uint32_t max_client_width = selmon->w.width - 2 * scroller_structs - gappih; selmon->sel->scroller_proportion = arg->f; selmon->sel->geom.width = max_client_width * arg->f; @@ -716,14 +715,26 @@ int centerwin(const Arg *arg) { Client *c = NULL; c = selmon->sel; - if (!c || c->isfullscreen) + if (!c || c->isfullscreen || c->ismaximizescreen) return 0; - if (!c->isfloating) - setfloating(c, true); - c->float_geom = setclient_coordinate_center(c, c->geom, 0, 0); - c->iscustomsize = 1; - resize(c, c->float_geom, 1); + if (c->isfloating) { + c->float_geom = setclient_coordinate_center(c, c->geom, 0, 0); + c->iscustomsize = 1; + resize(c, c->float_geom, 1); + return 0; + } + + if (!is_scroller_layout(selmon)) + return 0; + + if (selmon->pertag->ltidxs[selmon->pertag->curtag]->id == SCROLLER) { + c->geom.x = selmon->w.x + (selmon->w.width - c->geom.width) / 2; + } else { + c->geom.y = selmon->w.y + (selmon->w.height - c->geom.height) / 2; + } + + arrange(selmon, false); return 0; } @@ -809,7 +820,7 @@ int spawn_on_empty(const Arg *arg) { return 0; } else { view(arg, true); - spawn(arg); + spawn_shell(arg); } return 0; } @@ -836,90 +847,35 @@ int switch_keyboard_layout(const Arg *arg) { } xkb_layout_index_t next = (current + 1) % num_layouts; - // 2. 创建上下文 - struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); - if (!context) { - wlr_log(WLR_ERROR, "Failed to create XKB context"); - return 0; - } - - // 3. 分配并获取布局缩写 - const char **layout_ids = calloc(num_layouts, sizeof(char *)); - if (!layout_ids) { - wlr_log(WLR_ERROR, "Failed to allocate layout IDs"); - goto cleanup_context; - } - - for (int i = 0; i < num_layouts; i++) { - layout_ids[i] = - get_layout_abbr(xkb_keymap_layout_get_name(keyboard->keymap, i)); - if (!layout_ids[i]) { - wlr_log(WLR_ERROR, "Failed to get layout abbreviation"); - goto cleanup_layouts; - } - } - - // 4. 直接修改 rules.layout(保持原有逻辑) - struct xkb_rule_names rules = xkb_rules; - char *layout_buf = (char *)rules.layout; // 假设这是可修改的 - - // 清空原有内容(安全方式) - unsigned int layout_buf_size = strlen(layout_buf) + 1; - memset(layout_buf, 0, layout_buf_size); - - // 构建新的布局字符串 - for (int i = 0; i < num_layouts; i++) { - const char *layout = layout_ids[(next + i) % num_layouts]; - - if (i > 0) { - strncat(layout_buf, ",", layout_buf_size - strlen(layout_buf) - 1); - } - - if (strchr(layout, ',')) { - // 处理包含逗号的布局名 - char *quoted = malloc(strlen(layout) + 3); - if (quoted) { - snprintf(quoted, strlen(layout) + 3, "\"%s\"", layout); - strncat(layout_buf, quoted, - layout_buf_size - strlen(layout_buf) - 1); - free(quoted); - } - } else { - strncat(layout_buf, layout, - layout_buf_size - strlen(layout_buf) - 1); - } - } - - // 5. 创建新 keymap - struct xkb_keymap *new_keymap = - xkb_keymap_new_from_names(context, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS); - if (!new_keymap) { - wlr_log(WLR_ERROR, "Failed to create keymap for layouts: %s", - rules.layout); - goto cleanup_layouts; - } - // 6. 应用新 keymap - unsigned int depressed = keyboard->modifiers.depressed; - unsigned int latched = keyboard->modifiers.latched; - unsigned int locked = keyboard->modifiers.locked; + uint32_t depressed = keyboard->modifiers.depressed; + uint32_t latched = keyboard->modifiers.latched; + uint32_t locked = keyboard->modifiers.locked; - wlr_keyboard_set_keymap(keyboard, new_keymap); - wlr_keyboard_notify_modifiers(keyboard, depressed, latched, locked, 0); + wlr_keyboard_set_keymap(keyboard, keyboard->keymap); + wlr_keyboard_notify_modifiers(keyboard, depressed, latched, locked, next); keyboard->modifiers.group = 0; // 7. 更新 seat wlr_seat_set_keyboard(seat, keyboard); wlr_seat_keyboard_notify_modifiers(seat, &keyboard->modifiers); - // 8. 清理资源 - xkb_keymap_unref(new_keymap); + InputDevice *id; + wl_list_for_each(id, &inputdevices, link) { + if (id->wlr_device->type != WLR_INPUT_DEVICE_KEYBOARD) { + continue; + } -cleanup_layouts: - free(layout_ids); + struct wlr_keyboard *tkb = (struct wlr_keyboard *)id->device_data; -cleanup_context: - xkb_context_unref(context); + wlr_keyboard_set_keymap(tkb, keyboard->keymap); + wlr_keyboard_notify_modifiers(tkb, depressed, latched, locked, next); + tkb->modifiers.group = 0; + + // 7. 更新 seat + wlr_seat_set_keyboard(seat, tkb); + wlr_seat_keyboard_notify_modifiers(seat, &tkb->modifiers); + } printstatus(); return 0; @@ -929,7 +885,7 @@ int switch_layout(const Arg *arg) { int jk, ji; char *target_layout_name = NULL; - unsigned int len; + uint32_t len; if (config.circle_layout_count != 0) { for (jk = 0; jk < config.circle_layout_count; jk++) { @@ -960,7 +916,7 @@ int switch_layout(const Arg *arg) { break; } } - + clear_fullscreen_and_maximized_state(selmon); arrange(selmon, false); printstatus(); return 0; @@ -971,6 +927,7 @@ int switch_layout(const Arg *arg) { selmon->pertag->ltidxs[selmon->pertag->curtag]->name) == 0) { selmon->pertag->ltidxs[selmon->pertag->curtag] = jk == LENGTH(layouts) - 1 ? &layouts[0] : &layouts[jk + 1]; + clear_fullscreen_and_maximized_state(selmon); arrange(selmon, false); printstatus(); return 0; @@ -986,6 +943,13 @@ int switch_proportion_preset(const Arg *arg) { return 0; } + if (selmon->isoverview || !is_scroller_layout(selmon)) + return 0; + + if (selmon->visible_tiling_clients == 1 && + !scroller_ignore_proportion_single) + return 0; + if (selmon->sel) { for (int i = 0; i < config.scroller_proportion_preset_count; i++) { @@ -1006,7 +970,7 @@ int switch_proportion_preset(const Arg *arg) { target_proportion = config.scroller_proportion_preset[0]; } - unsigned int max_client_width = + uint32_t max_client_width = selmon->w.width - 2 * scroller_structs - gappih; selmon->sel->scroller_proportion = target_proportion; selmon->sel->geom.width = max_client_width * target_proportion; @@ -1023,7 +987,7 @@ int tag(const Arg *arg) { } int tagmon(const Arg *arg) { - Monitor *m = NULL; + Monitor *m = NULL, *cm = NULL; Client *c = focustop(selmon); if (!c) @@ -1032,11 +996,12 @@ int tagmon(const Arg *arg) { if (arg->i != UNDIR) { m = dirtomon(arg->i); } else if (arg->v) { - wl_list_for_each(m, &mons, link) { - if (!m->wlr_output->enabled) { + wl_list_for_each(cm, &mons, link) { + if (!cm->wlr_output->enabled) { continue; } - if (regex_match(arg->v, m->wlr_output->name)) { + if (regex_match(arg->v, cm->wlr_output->name)) { + m = cm; break; } } @@ -1044,11 +1009,17 @@ int tagmon(const Arg *arg) { return 0; } - if (!m || !m->wlr_output->enabled || m == c->mon) + if (!m || !m->wlr_output->enabled) return 0; - unsigned int newtags = arg->ui ? c->tags : 0; - unsigned int target; + uint32_t newtags = arg->ui ? arg->ui : arg->i2 ? c->tags : 0; + uint32_t target; + + if (c->mon == m) { + view(&(Arg){.ui = newtags}, true); + return 0; + } + if (c == selmon->sel) { selmon->sel = NULL; } @@ -1065,6 +1036,7 @@ int tagmon(const Arg *arg) { selmon = c->mon; c->float_geom = setclient_coordinate_center(c, c->float_geom, 0, 0); + // 重新计算居中的坐标 // 重新计算居中的坐标 if (c->isfloating) { c->geom = c->float_geom; @@ -1132,7 +1104,7 @@ int toggle_named_scratchpad(const Arg *arg) { if (!target_client && arg->v3) { Arg arg_spawn = {.v = arg->v3}; - spawn(&arg_spawn); + spawn_shell(&arg_spawn); return 0; } @@ -1161,7 +1133,7 @@ int toggle_scratchpad(const Arg *arg) { continue; } - if (single_scratchpad && c->isnamedscratchpad && !c->isminied) { + if (single_scratchpad && c->isnamedscratchpad && !c->isminimized) { set_minimized(c); continue; } @@ -1193,7 +1165,7 @@ int togglefloating(const Arg *arg) { if (!sel) return 0; - if ((sel->isfullscreen || sel->ismaxmizescreen)) { + if ((sel->isfullscreen || sel->ismaximizescreen)) { sel->isfloating = 1; } else { sel->isfloating = !sel->isfloating; @@ -1241,7 +1213,7 @@ int togglegaps(const Arg *arg) { return 0; } -int togglemaxmizescreen(const Arg *arg) { +int togglemaximizescreen(const Arg *arg) { Client *sel = focustop(selmon); if (!sel) return 0; @@ -1250,10 +1222,10 @@ int togglemaxmizescreen(const Arg *arg) { sel->is_in_scratchpad = 0; sel->isnamedscratchpad = 0; - if (sel->ismaxmizescreen) - setmaxmizescreen(sel, 0); + if (sel->ismaximizescreen) + setmaximizescreen(sel, 0); else - setmaxmizescreen(sel, 1); + setmaximizescreen(sel, 1); setborder_color(sel); return 0; @@ -1281,7 +1253,7 @@ int toggleoverlay(const Arg *arg) { } int toggletag(const Arg *arg) { - unsigned int newtags; + uint32_t newtags; Client *sel = focustop(selmon); if (!sel) return 0; @@ -1304,8 +1276,8 @@ int toggletag(const Arg *arg) { } int toggleview(const Arg *arg) { - unsigned int newtagset; - unsigned int target; + uint32_t newtagset; + uint32_t target; target = arg->ui == 0 ? ~0 & TAGMASK : arg->ui; @@ -1322,7 +1294,7 @@ int toggleview(const Arg *arg) { } int viewtoleft(const Arg *arg) { - unsigned int target = selmon->tagset[selmon->seltags]; + uint32_t target = selmon->tagset[selmon->seltags]; if (selmon->isoverview || selmon->pertag->curtag == 0) { return 0; @@ -1345,7 +1317,7 @@ int viewtoright(const Arg *arg) { if (selmon->isoverview || selmon->pertag->curtag == 0) { return 0; } - unsigned int target = selmon->tagset[selmon->seltags]; + uint32_t target = selmon->tagset[selmon->seltags]; target <<= 1; if (!selmon || (target) == selmon->tagset[selmon->seltags]) @@ -1359,9 +1331,8 @@ int viewtoright(const Arg *arg) { } int viewtoleft_have_client(const Arg *arg) { - unsigned int n; - unsigned int current = - get_tags_first_tag_num(selmon->tagset[selmon->seltags]); + uint32_t n; + uint32_t current = get_tags_first_tag_num(selmon->tagset[selmon->seltags]); bool found = false; if (selmon->isoverview) { @@ -1384,9 +1355,8 @@ int viewtoleft_have_client(const Arg *arg) { } int viewtoright_have_client(const Arg *arg) { - unsigned int n; - unsigned int current = - get_tags_first_tag_num(selmon->tagset[selmon->seltags]); + uint32_t n; + uint32_t current = get_tags_first_tag_num(selmon->tagset[selmon->seltags]); bool found = false; if (selmon->isoverview) { @@ -1408,8 +1378,22 @@ int viewtoright_have_client(const Arg *arg) { return 0; } +int viewcrossmon(const Arg *arg) { + focusmon(&(Arg){.v = arg->v, .i = UNDIR}); + view_in_mon(arg, true, selmon, true); + return 0; +} + +int tagcrossmon(const Arg *arg) { + if (!selmon->sel) + return 0; + + tagmon(&(Arg){.ui = arg->ui, .i = UNDIR, .v = arg->v}); + return 0; +} + int comboview(const Arg *arg) { - unsigned int newtags = arg->ui & TAGMASK; + uint32_t newtags = arg->ui & TAGMASK; if (!newtags || !selmon) return 0; @@ -1472,7 +1456,7 @@ int minimized(const Arg *arg) { if (selmon && selmon->isoverview) return 0; - if (selmon->sel && !selmon->sel->isminied) { + if (selmon->sel && !selmon->sel->isminimized) { set_minimized(selmon->sel); } return 0; @@ -1481,21 +1465,21 @@ int minimized(const Arg *arg) { int toggleoverview(const Arg *arg) { Client *c = NULL; - if (selmon->isoverview && ov_tab_mode && arg->i != -1 && selmon->sel) { + if (selmon->isoverview && ov_tab_mode && arg->i != 1 && selmon->sel) { focusstack(&(Arg){.i = 1}); return 0; } selmon->isoverview ^= 1; - unsigned int target; - unsigned int visible_client_number = 0; + uint32_t target; + uint32_t visible_client_number = 0; if (selmon->isoverview) { - wl_list_for_each(c, &clients, - link) if (c && c->mon == selmon && - !client_is_unmanaged(c) && - !client_should_ignore_focus(c) && - !c->isminied && !c->isunglobal) { + wl_list_for_each(c, &clients, link) if (c && c->mon == selmon && + !client_is_unmanaged(c) && + !client_is_x11_popup(c) && + !c->isminimized && + !c->isunglobal) { visible_client_number++; } if (visible_client_number > 0) { @@ -1518,24 +1502,65 @@ int toggleoverview(const Arg *arg) { if (selmon->isoverview) { wl_list_for_each(c, &clients, link) { if (c && c->mon == selmon && !client_is_unmanaged(c) && - !client_should_ignore_focus(c) && !c->isunglobal) + !client_is_x11_popup(c) && !c->isunglobal) overview_backup(c); } } else { wl_list_for_each(c, &clients, link) { if (c && c->mon == selmon && !c->iskilling && !client_is_unmanaged(c) && !c->isunglobal && - !client_should_ignore_focus(c) && client_surface(c)->mapped) + !client_is_x11_popup(c) && client_surface(c)->mapped) overview_restore(c, &(Arg){.ui = target}); } } view(&(Arg){.ui = target}, false); - if (ov_tab_mode && selmon->isoverview && selmon->sel) { - focusstack(&(Arg){.i = 1}); - } - refresh_monitors_workspaces_status(selmon); return 0; } + +int disable_monitor(const Arg *arg) { + Monitor *m = NULL; + struct wlr_output_state state = {0}; + wl_list_for_each(m, &mons, link) { + if (regex_match(arg->v, m->wlr_output->name)) { + wlr_output_state_set_enabled(&state, false); + wlr_output_commit_state(m->wlr_output, &state); + m->asleep = 1; + updatemons(NULL, NULL); + break; + } + } + return 0; +} + +int enable_monitor(const Arg *arg) { + Monitor *m = NULL; + struct wlr_output_state state = {0}; + wl_list_for_each(m, &mons, link) { + if (regex_match(arg->v, m->wlr_output->name)) { + wlr_output_state_set_enabled(&state, true); + wlr_output_commit_state(m->wlr_output, &state); + m->asleep = 0; + updatemons(NULL, NULL); + break; + } + } + return 0; +} + +int toggle_monitor(const Arg *arg) { + Monitor *m = NULL; + struct wlr_output_state state = {0}; + wl_list_for_each(m, &mons, link) { + if (regex_match(arg->v, m->wlr_output->name)) { + wlr_output_state_set_enabled(&state, !m->wlr_output->enabled); + wlr_output_commit_state(m->wlr_output, &state); + m->asleep = !m->wlr_output->enabled; + updatemons(NULL, NULL); + break; + } + } + return 0; +} diff --git a/src/ext-protocol/all.h b/src/ext-protocol/all.h index 1ec7407e..4671c00c 100644 --- a/src/ext-protocol/all.h +++ b/src/ext-protocol/all.h @@ -1,5 +1,5 @@ #include "dwl-ipc.h" #include "ext-workspace.h" #include "foreign-toplevel.h" -#include "tablet.h" +#include "tearing.h" #include "text-input.h" diff --git a/src/ext-protocol/dwl-ipc.h b/src/ext-protocol/dwl-ipc.h index 23207d01..eda3f49f 100644 --- a/src/ext-protocol/dwl-ipc.h +++ b/src/ext-protocol/dwl-ipc.h @@ -1,12 +1,11 @@ #include "dwl-ipc-unstable-v2-protocol.h" static void dwl_ipc_manager_bind(struct wl_client *client, void *data, - unsigned int version, unsigned int id); + uint32_t version, uint32_t id); static void dwl_ipc_manager_destroy(struct wl_resource *resource); static void dwl_ipc_manager_get_output(struct wl_client *client, struct wl_resource *resource, - unsigned int id, - struct wl_resource *output); + uint32_t id, struct wl_resource *output); static void dwl_ipc_manager_release(struct wl_client *client, struct wl_resource *resource); static void dwl_ipc_output_destroy(struct wl_resource *resource); @@ -14,15 +13,14 @@ static void dwl_ipc_output_printstatus(Monitor *monitor); static void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output); static void dwl_ipc_output_set_client_tags(struct wl_client *client, struct wl_resource *resource, - unsigned int and_tags, - unsigned int xor_tags); + uint32_t and_tags, + uint32_t xor_tags); static void dwl_ipc_output_set_layout(struct wl_client *client, struct wl_resource *resource, - unsigned int index); + uint32_t index); static void dwl_ipc_output_set_tags(struct wl_client *client, struct wl_resource *resource, - unsigned int tagmask, - unsigned int toggle_tagset); + uint32_t tagmask, uint32_t toggle_tagset); static void dwl_ipc_output_quit(struct wl_client *client, struct wl_resource *resource); static void dwl_ipc_output_dispatch(struct wl_client *client, @@ -46,7 +44,7 @@ static struct zdwl_ipc_output_v2_interface dwl_output_implementation = { .set_client_tags = dwl_ipc_output_set_client_tags}; void dwl_ipc_manager_bind(struct wl_client *client, void *data, - unsigned int version, unsigned int id) { + uint32_t version, uint32_t id) { struct wl_resource *manager_resource = wl_resource_create(client, &zdwl_ipc_manager_v2_interface, version, id); if (!manager_resource) { @@ -59,7 +57,7 @@ void dwl_ipc_manager_bind(struct wl_client *client, void *data, zdwl_ipc_manager_v2_send_tags(manager_resource, LENGTH(tags)); - for (unsigned int i = 0; i < LENGTH(layouts); i++) + for (uint32_t i = 0; i < LENGTH(layouts); i++) zdwl_ipc_manager_v2_send_layout(manager_resource, layouts[i].symbol); } @@ -68,7 +66,7 @@ void dwl_ipc_manager_destroy(struct wl_resource *resource) { } void dwl_ipc_manager_get_output(struct wl_client *client, - struct wl_resource *resource, unsigned int id, + struct wl_resource *resource, uint32_t id, struct wl_resource *output) { DwlIpcOutput *ipc_output; struct wlr_output *op = wlr_output_from_resource(output); @@ -101,19 +99,22 @@ static void dwl_ipc_output_destroy(struct wl_resource *resource) { free(ipc_output); } +// 修改IPC输出函数,接受掩码参数 void dwl_ipc_output_printstatus(Monitor *monitor) { DwlIpcOutput *ipc_output; wl_list_for_each(ipc_output, &monitor->dwl_ipc_outputs, link) dwl_ipc_output_printstatus_to(ipc_output); } +// 修改主IPC输出函数,根据掩码发送相应事件 void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) { Monitor *monitor = ipc_output->mon; Client *c = NULL, *focused = NULL; struct wlr_keyboard *keyboard; xkb_layout_index_t current; int tagmask, state, numclients, focused_client, tag; - const char *title, *appid, *symbol, *kb_layout; + const char *title, *appid, *symbol; + char kb_layout[32]; focused = focustop(monitor); zdwl_ipc_output_v2_send_active(ipc_output->resource, monitor == selmon); @@ -149,8 +150,8 @@ void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) { keyboard = &kb_group->wlr_group->keyboard; current = xkb_state_serialize_layout(keyboard->xkb_state, XKB_STATE_LAYOUT_EFFECTIVE); - kb_layout = - get_layout_abbr(xkb_keymap_layout_get_name(keyboard->keymap, current)); + get_layout_abbr(kb_layout, + xkb_keymap_layout_get_name(keyboard->keymap, current)); zdwl_ipc_output_v2_send_layout( ipc_output->resource, @@ -204,17 +205,22 @@ void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) { zdwl_ipc_output_v2_send_keymode(ipc_output->resource, keymode.mode); } + if (wl_resource_get_version(ipc_output->resource) >= + ZDWL_IPC_OUTPUT_V2_SCALEFACTOR_SINCE_VERSION) { + zdwl_ipc_output_v2_send_scalefactor(ipc_output->resource, + monitor->wlr_output->scale * 100); + } + zdwl_ipc_output_v2_send_frame(ipc_output->resource); } void dwl_ipc_output_set_client_tags(struct wl_client *client, struct wl_resource *resource, - unsigned int and_tags, - unsigned int xor_tags) { + uint32_t and_tags, uint32_t xor_tags) { DwlIpcOutput *ipc_output; Monitor *monitor = NULL; Client *selected_client = NULL; - unsigned int newtags = 0; + uint32_t newtags = 0; ipc_output = wl_resource_get_user_data(resource); if (!ipc_output) @@ -237,8 +243,7 @@ void dwl_ipc_output_set_client_tags(struct wl_client *client, } void dwl_ipc_output_set_layout(struct wl_client *client, - struct wl_resource *resource, - unsigned int index) { + struct wl_resource *resource, uint32_t index) { DwlIpcOutput *ipc_output; Monitor *monitor = NULL; @@ -251,16 +256,17 @@ void dwl_ipc_output_set_layout(struct wl_client *client, index = 0; monitor->pertag->ltidxs[monitor->pertag->curtag] = &layouts[index]; + clear_fullscreen_and_maximized_state(monitor); arrange(monitor, false); printstatus(); } void dwl_ipc_output_set_tags(struct wl_client *client, - struct wl_resource *resource, unsigned int tagmask, - unsigned int toggle_tagset) { + struct wl_resource *resource, uint32_t tagmask, + uint32_t toggle_tagset) { DwlIpcOutput *ipc_output; Monitor *monitor = NULL; - unsigned int newtags = tagmask & TAGMASK; + uint32_t newtags = tagmask & TAGMASK; ipc_output = wl_resource_get_user_data(resource); if (!ipc_output) diff --git a/src/ext-protocol/ext-workspace.h b/src/ext-protocol/ext-workspace.h index 6e1a747b..8ff53cc0 100644 --- a/src/ext-protocol/ext-workspace.h +++ b/src/ext-protocol/ext-workspace.h @@ -1,14 +1,14 @@ #include "wlr_ext_workspace_v1.h" #define EXT_WORKSPACE_ENABLE_CAPS \ - WLR_EXT_WORKSPACE_HANDLE_V1_CAP_ACTIVATE | \ - WLR_EXT_WORKSPACE_HANDLE_V1_CAP_DEACTIVATE + EXT_WORKSPACE_HANDLE_V1_WORKSPACE_CAPABILITIES_ACTIVATE | \ + EXT_WORKSPACE_HANDLE_V1_WORKSPACE_CAPABILITIES_DEACTIVATE typedef struct Monitor Monitor; struct workspace { struct wl_list link; // Link in global workspaces list - unsigned int tag; // Numeric identifier (1-9, 0=overview) + uint32_t tag; // Numeric identifier (1-9, 0=overview) Monitor *m; // Associated monitor struct wlr_ext_workspace_handle_v1 *ext_workspace; // Protocol object /* Event listeners */ @@ -22,7 +22,7 @@ struct wlr_ext_workspace_manager_v1 *ext_manager; struct wl_list workspaces; void goto_workspace(struct workspace *target) { - unsigned int tag; + uint32_t tag; tag = 1 << (target->tag - 1); if (target->tag == 0) { toggleoverview(&(Arg){.i = -1}); @@ -33,7 +33,7 @@ void goto_workspace(struct workspace *target) { } void toggle_workspace(struct workspace *target) { - unsigned int tag; + uint32_t tag; tag = 1 << (target->tag - 1); if (target->tag == 0) { toggleview(&(Arg){.i = -1}); @@ -47,6 +47,11 @@ static void handle_ext_workspace_activate(struct wl_listener *listener, void *data) { struct workspace *workspace = wl_container_of(listener, workspace, activate); + + if (workspace->m->isoverview) { + return; + } + goto_workspace(workspace); wlr_log(WLR_INFO, "ext activating workspace %d", workspace->tag); } @@ -55,11 +60,16 @@ static void handle_ext_workspace_deactivate(struct wl_listener *listener, void *data) { struct workspace *workspace = wl_container_of(listener, workspace, deactivate); + + if (workspace->m->isoverview) { + return; + } + toggle_workspace(workspace); wlr_log(WLR_INFO, "ext deactivating workspace %d", workspace->tag); } -static const char *get_name_from_tag(unsigned int tag) { +static const char *get_name_from_tag(uint32_t tag) { static const char *names[] = {"overview", "1", "2", "3", "4", "5", "6", "7", "8", "9"}; return (tag < sizeof(names) / sizeof(names[0])) ? names[tag] : NULL; @@ -82,7 +92,7 @@ void cleanup_workspaces_by_monitor(Monitor *m) { } } -static void remove_workspace_by_tag(unsigned int tag, Monitor *m) { +static void remove_workspace_by_tag(uint32_t tag, Monitor *m) { struct workspace *workspace, *tmp; wl_list_for_each_safe(workspace, tmp, &workspaces, link) { if (workspace->tag == tag && workspace->m == m) { @@ -117,7 +127,7 @@ static void add_workspace_by_tag(int tag, Monitor *m) { void dwl_ext_workspace_printstatus(Monitor *m) { struct workspace *w; - unsigned int tag_status = 0; + uint32_t tag_status = 0; wl_list_for_each(w, &workspaces, link) { if (w && w->m == m) { @@ -134,6 +144,10 @@ void dwl_ext_workspace_printstatus(Monitor *m) { if (!w->m->pertag->no_hide[w->tag]) wlr_ext_workspace_handle_v1_set_hidden(w->ext_workspace, true); + else { + wlr_ext_workspace_handle_v1_set_hidden(w->ext_workspace, + false); + } } if ((m->tagset[m->seltags] & (1 << (w->tag - 1)) & TAGMASK) || diff --git a/src/ext-protocol/foreign-toplevel.h b/src/ext-protocol/foreign-toplevel.h index adfcd21b..01c384fb 100644 --- a/src/ext-protocol/foreign-toplevel.h +++ b/src/ext-protocol/foreign-toplevel.h @@ -4,17 +4,12 @@ static struct wlr_foreign_toplevel_manager_v1 *foreign_toplevel_manager; void handle_foreign_activate_request(struct wl_listener *listener, void *data) { Client *c = wl_container_of(listener, c, foreign_activate_request); - unsigned int target; + uint32_t target; - if (c && c->swallowing) + if (c->swallowing) return; - if (c && !c->isminied && c == selmon->sel) { - set_minimized(c); - return; - } - - if (c->isminied) { + if (c->isminimized) { c->is_in_scratchpad = 0; c->isnamedscratchpad = 0; c->is_scratchpad_show = 0; @@ -27,29 +22,82 @@ void handle_foreign_activate_request(struct wl_listener *listener, void *data) { target = get_tags_first_tag(c->tags); view_in_mon(&(Arg){.ui = target}, true, c->mon, true); focusclient(c, 1); - wlr_foreign_toplevel_handle_v1_set_activated(c->foreign_toplevel, true); +} + +void handle_foreign_maximize_request(struct wl_listener *listener, void *data) { + Client *c = wl_container_of(listener, c, foreign_maximize_request); + struct wlr_foreign_toplevel_handle_v1_maximized_event *event = data; + + if (c->swallowing) + return; + + if (c->ismaximizescreen && !event->maximized) { + setmaximizescreen(c, 0); + return; + } + + if (!c->ismaximizescreen && event->maximized) { + setmaximizescreen(c, 1); + return; + } +} + +void handle_foreign_minimize_request(struct wl_listener *listener, void *data) { + Client *c = wl_container_of(listener, c, foreign_minimize_request); + struct wlr_foreign_toplevel_handle_v1_minimized_event *event = data; + + if (c->swallowing) + return; + + if (!c->isminimized && event->minimized) { + set_minimized(c); + return; + } + + if (c->isminimized && !event->minimized) { + c->is_in_scratchpad = 0; + c->isnamedscratchpad = 0; + c->is_scratchpad_show = 0; + setborder_color(c); + show_hide_client(c); + arrange(c->mon, true); + return; + } } void handle_foreign_fullscreen_request(struct wl_listener *listener, void *data) { - return; + + Client *c = wl_container_of(listener, c, foreign_fullscreen_request); + struct wlr_foreign_toplevel_handle_v1_fullscreen_event *event = data; + + if (c->swallowing) + return; + + if (c->isfullscreen && !event->fullscreen) { + setfullscreen(c, 0); + return; + } + + if (!c->isfullscreen && event->fullscreen) { + setfullscreen(c, 1); + return; + } } void handle_foreign_close_request(struct wl_listener *listener, void *data) { Client *c = wl_container_of(listener, c, foreign_close_request); - if (c) { - pending_kill_client(c); - } + pending_kill_client(c); } void handle_foreign_destroy(struct wl_listener *listener, void *data) { Client *c = wl_container_of(listener, c, foreign_destroy); - if (c) { - wl_list_remove(&c->foreign_activate_request.link); - wl_list_remove(&c->foreign_fullscreen_request.link); - wl_list_remove(&c->foreign_close_request.link); - wl_list_remove(&c->foreign_destroy.link); - } + wl_list_remove(&c->foreign_activate_request.link); + wl_list_remove(&c->foreign_minimize_request.link); + wl_list_remove(&c->foreign_maximize_request.link); + wl_list_remove(&c->foreign_fullscreen_request.link); + wl_list_remove(&c->foreign_close_request.link); + wl_list_remove(&c->foreign_destroy.link); } void remove_foreign_topleve(Client *c) { @@ -67,6 +115,10 @@ void add_foreign_toplevel(Client *c) { if (c->foreign_toplevel) { LISTEN(&(c->foreign_toplevel->events.request_activate), &c->foreign_activate_request, handle_foreign_activate_request); + LISTEN(&(c->foreign_toplevel->events.request_minimize), + &c->foreign_minimize_request, handle_foreign_minimize_request); + LISTEN(&(c->foreign_toplevel->events.request_maximize), + &c->foreign_maximize_request, handle_foreign_maximize_request); LISTEN(&(c->foreign_toplevel->events.request_fullscreen), &c->foreign_fullscreen_request, handle_foreign_fullscreen_request); diff --git a/src/ext-protocol/tearing.h b/src/ext-protocol/tearing.h new file mode 100644 index 00000000..8e02656a --- /dev/null +++ b/src/ext-protocol/tearing.h @@ -0,0 +1,171 @@ +#include + +struct tearing_controller { + struct wlr_tearing_control_v1 *tearing_control; + struct wl_listener set_hint; + struct wl_listener destroy; +}; + +struct wlr_tearing_control_manager_v1 *tearing_control; +struct wl_listener tearing_new_object; + +static void handle_controller_set_hint(struct wl_listener *listener, + void *data) { + struct tearing_controller *controller = + wl_container_of(listener, controller, set_hint); + Client *c = NULL; + + toplevel_from_wlr_surface(controller->tearing_control->surface, &c, NULL); + + if (c) { + /* + * tearing_control->current is actually an enum: + * WP_TEARING_CONTROL_V1_PRESENTATION_HINT_VSYNC = 0 + * WP_TEARING_CONTROL_V1_PRESENTATION_HINT_ASYNC = 1 + * + * Using it as a bool here allows us to not ship the XML. + */ + c->tearing_hint = controller->tearing_control->current; + } +} + +static void handle_controller_destroy(struct wl_listener *listener, + void *data) { + struct tearing_controller *controller = + wl_container_of(listener, controller, destroy); + wl_list_remove(&controller->set_hint.link); + wl_list_remove(&controller->destroy.link); + free(controller); +} + +void handle_tearing_new_object(struct wl_listener *listener, void *data) { + struct wlr_tearing_control_v1 *new_tearing_control = data; + + enum wp_tearing_control_v1_presentation_hint hint = + wlr_tearing_control_manager_v1_surface_hint_from_surface( + tearing_control, new_tearing_control->surface); + wlr_log(WLR_DEBUG, "New presentation hint %d received for surface %p", hint, + new_tearing_control->surface); + + struct tearing_controller *controller = + ecalloc(1, sizeof(struct tearing_controller)); + controller->tearing_control = new_tearing_control; + + controller->set_hint.notify = handle_controller_set_hint; + wl_signal_add(&new_tearing_control->events.set_hint, &controller->set_hint); + + controller->destroy.notify = handle_controller_destroy; + wl_signal_add(&new_tearing_control->events.destroy, &controller->destroy); +} + +bool check_tearing_frame_allow(Monitor *m) { + /* never allow tearing when disabled */ + if (!allow_tearing) { + return false; + } + + Client *c = selmon->sel; + + /* tearing is only allowed for the output with the active client */ + if (!c || c->mon != m) { + return false; + } + + /* allow tearing for any window when requested or forced */ + if (allow_tearing == TEARING_ENABLED) { + if (c->force_tearing == STATE_UNSPECIFIED) { + return c->tearing_hint; + } else { + return c->force_tearing == STATE_ENABLED; + } + } + + /* remaining tearing options apply only to full-screen windows */ + if (!c->isfullscreen) { + return false; + } + + if (c->force_tearing == STATE_UNSPECIFIED) { + /* honor the tearing hint or the fullscreen-force preference */ + return c->tearing_hint || allow_tearing == TEARING_FULLSCREEN_ONLY; + } + + /* honor tearing as requested by action */ + return c->force_tearing == STATE_ENABLED; +} + +bool custom_wlr_scene_output_commit(struct wlr_scene_output *scene_output, + struct wlr_output_state *state) { + struct wlr_output *wlr_output = scene_output->output; + Monitor *m = wlr_output->data; + + // 检查是否需要帧 + if (!wlr_scene_output_needs_frame(scene_output)) { + wlr_log(WLR_DEBUG, "No frame needed for output %s", wlr_output->name); + return true; + } + + // 构建输出状态 + if (!wlr_scene_output_build_state(scene_output, state, NULL)) { + wlr_log(WLR_ERROR, "Failed to build output state for %s", + wlr_output->name); + return false; + } + + // 测试撕裂翻页 + if (state->tearing_page_flip) { + if (!wlr_output_test_state(wlr_output, state)) { + state->tearing_page_flip = false; + } + } + + // 尝试提交 + bool committed = wlr_output_commit_state(wlr_output, state); + + // 如果启用撕裂翻页但提交失败,重试禁用撕裂翻页 + if (!committed && state->tearing_page_flip) { + wlr_log(WLR_DEBUG, "Retrying commit without tearing for %s", + wlr_output->name); + state->tearing_page_flip = false; + committed = wlr_output_commit_state(wlr_output, state); + } + + // 处理状态清理 + if (committed) { + wlr_log(WLR_DEBUG, "Successfully committed output %s", + wlr_output->name); + if (state == &m->pending) { + wlr_output_state_finish(&m->pending); + wlr_output_state_init(&m->pending); + } + } else { + wlr_log(WLR_ERROR, "Failed to commit output %s", wlr_output->name); + // 即使提交失败,也清理状态避免积累 + if (state == &m->pending) { + wlr_output_state_finish(&m->pending); + wlr_output_state_init(&m->pending); + } + return false; + } + + return true; +} + +void apply_tear_state(Monitor *m) { + if (wlr_scene_output_needs_frame(m->scene_output)) { + wlr_output_state_init(&m->pending); + if (wlr_scene_output_build_state(m->scene_output, &m->pending, NULL)) { + struct wlr_output_state *pending = &m->pending; + pending->tearing_page_flip = true; + + if (!custom_wlr_scene_output_commit(m->scene_output, pending)) { + wlr_log(WLR_ERROR, "Failed to commit output %s", + m->scene_output->output->name); + } + } else { + wlr_log(WLR_ERROR, "Failed to build state for output %s", + m->scene_output->output->name); + wlr_output_state_finish(&m->pending); + } + } +} \ No newline at end of file diff --git a/src/ext-protocol/wlr_ext_workspace_v1.c b/src/ext-protocol/wlr_ext_workspace_v1.c index 3f80e9f2..2d781b34 100644 --- a/src/ext-protocol/wlr_ext_workspace_v1.c +++ b/src/ext-protocol/wlr_ext_workspace_v1.c @@ -29,7 +29,7 @@ struct wlr_ext_workspace_v1_request { // ACTIVATE / DEACTIVATE / ASSIGN / REMOVE struct wlr_ext_workspace_handle_v1 *workspace; - struct wl_list link; // wlr_ext_workspace_manager_client_v1.requests + struct wl_list link; // wlr_ext_workspace_manager_v1_resource.requests }; struct wlr_ext_workspace_v1_group_output { @@ -41,33 +41,40 @@ struct wlr_ext_workspace_v1_group_output { }; // These structs wrap wl_resource of each interface to access the request queue -// (wlr_ext_workspace_manager_client_v1.requests) assigned per manager resource +// (wlr_ext_workspace_manager_v1_resource.requests) assigned per manager +// resource -struct wlr_ext_workspace_manager_client_v1 { +struct wlr_ext_workspace_manager_v1_resource { struct wl_resource *resource; struct wlr_ext_workspace_manager_v1 *manager; - struct wl_list requests; // wlr_ext_workspace_v1_request.link - struct wl_list link; // wlr_ext_workspace_manager_v1.clients + struct wl_list requests; // wlr_ext_workspace_v1_request.link + struct wl_list workspace_resources; // wlr_ext_workspace_v1_resource.link + struct wl_list group_resources; // wlr_ext_workspace_group_v1_resource.link + struct wl_list link; // wlr_ext_workspace_manager_v1.resources }; -struct wlr_ext_workspace_group_client_v1 { +struct wlr_ext_workspace_group_v1_resource { struct wl_resource *resource; struct wlr_ext_workspace_group_handle_v1 *group; - struct wlr_ext_workspace_manager_client_v1 *manager; - struct wl_list link; // wlr_ext_workspace_group_v1.clients + struct wlr_ext_workspace_manager_v1_resource *manager; + struct wl_list link; // wlr_ext_workspace_group_v1.resources + struct wl_list + manager_resource_link; // wlr_ext_workspace_manager_v1_resource.group_resources }; -struct wlr_ext_workspace_client_v1 { +struct wlr_ext_workspace_v1_resource { struct wl_resource *resource; struct wlr_ext_workspace_handle_v1 *workspace; - struct wlr_ext_workspace_manager_client_v1 *manager; - struct wl_list link; // wlr_ext_workspace_v1.clients + struct wlr_ext_workspace_manager_v1_resource *manager; + struct wl_list link; // wlr_ext_workspace_v1.resources + struct wl_list + manager_resource_link; // wlr_ext_workspace_manager_v1_resource.workspace_resources }; static const struct ext_workspace_group_handle_v1_interface group_impl; -static struct wlr_ext_workspace_group_client_v1 * -group_client_from_resource(struct wl_resource *resource) { +static struct wlr_ext_workspace_group_v1_resource * +group_resource_from_resource(struct wl_resource *resource) { assert(wl_resource_instance_of( resource, &ext_workspace_group_handle_v1_interface, &group_impl)); return wl_resource_get_user_data(resource); @@ -75,8 +82,8 @@ group_client_from_resource(struct wl_resource *resource) { static const struct ext_workspace_handle_v1_interface workspace_impl; -static struct wlr_ext_workspace_client_v1 * -workspace_client_from_resource(struct wl_resource *resource) { +static struct wlr_ext_workspace_v1_resource * +workspace_resource_from_resource(struct wl_resource *resource) { assert(wl_resource_instance_of(resource, &ext_workspace_handle_v1_interface, &workspace_impl)); return wl_resource_get_user_data(resource); @@ -84,8 +91,8 @@ workspace_client_from_resource(struct wl_resource *resource) { static const struct ext_workspace_manager_v1_interface manager_impl; -static struct wlr_ext_workspace_manager_client_v1 * -manager_client_from_resource(struct wl_resource *resource) { +static struct wlr_ext_workspace_manager_v1_resource * +manager_resource_from_resource(struct wl_resource *resource) { assert(wl_resource_instance_of( resource, &ext_workspace_manager_v1_interface, &manager_impl)); return wl_resource_get_user_data(resource); @@ -98,9 +105,9 @@ static void workspace_handle_destroy(struct wl_client *client, static void workspace_handle_activate(struct wl_client *client, struct wl_resource *workspace_resource) { - struct wlr_ext_workspace_client_v1 *workspace = - workspace_client_from_resource(workspace_resource); - if (!workspace) { + struct wlr_ext_workspace_v1_resource *workspace_res = + workspace_resource_from_resource(workspace_resource); + if (!workspace_res) { return; } @@ -110,16 +117,16 @@ static void workspace_handle_activate(struct wl_client *client, return; } req->type = WLR_EXT_WORKSPACE_V1_REQUEST_ACTIVATE; - req->workspace = workspace->workspace; - wl_list_insert(workspace->manager->requests.prev, &req->link); + req->workspace = workspace_res->workspace; + wl_list_insert(workspace_res->manager->requests.prev, &req->link); } static void workspace_handle_deactivate(struct wl_client *client, struct wl_resource *workspace_resource) { - struct wlr_ext_workspace_client_v1 *workspace = - workspace_client_from_resource(workspace_resource); - if (!workspace) { + struct wlr_ext_workspace_v1_resource *workspace_res = + workspace_resource_from_resource(workspace_resource); + if (!workspace_res) { return; } @@ -129,18 +136,18 @@ workspace_handle_deactivate(struct wl_client *client, return; } req->type = WLR_EXT_WORKSPACE_V1_REQUEST_DEACTIVATE; - req->workspace = workspace->workspace; - wl_list_insert(workspace->manager->requests.prev, &req->link); + req->workspace = workspace_res->workspace; + wl_list_insert(workspace_res->manager->requests.prev, &req->link); } static void workspace_handle_assign(struct wl_client *client, struct wl_resource *workspace_resource, struct wl_resource *group_resource) { - struct wlr_ext_workspace_client_v1 *workspace = - workspace_client_from_resource(workspace_resource); - struct wlr_ext_workspace_group_client_v1 *group = - group_client_from_resource(group_resource); - if (!workspace || !group) { + struct wlr_ext_workspace_v1_resource *workspace_res = + workspace_resource_from_resource(workspace_resource); + struct wlr_ext_workspace_group_v1_resource *group_res = + group_resource_from_resource(group_resource); + if (!workspace_res || !group_res) { return; } @@ -150,16 +157,16 @@ static void workspace_handle_assign(struct wl_client *client, return; } req->type = WLR_EXT_WORKSPACE_V1_REQUEST_ASSIGN; - req->group = group->group; - req->workspace = workspace->workspace; - wl_list_insert(workspace->manager->requests.prev, &req->link); + req->group = group_res->group; + req->workspace = workspace_res->workspace; + wl_list_insert(workspace_res->manager->requests.prev, &req->link); } static void workspace_handle_remove(struct wl_client *client, struct wl_resource *workspace_resource) { - struct wlr_ext_workspace_client_v1 *workspace = - workspace_client_from_resource(workspace_resource); - if (!workspace) { + struct wlr_ext_workspace_v1_resource *workspace_res = + workspace_resource_from_resource(workspace_resource); + if (!workspace_res) { return; } @@ -169,8 +176,8 @@ static void workspace_handle_remove(struct wl_client *client, return; } req->type = WLR_EXT_WORKSPACE_V1_REQUEST_REMOVE; - req->workspace = workspace->workspace; - wl_list_insert(workspace->manager->requests.prev, &req->link); + req->workspace = workspace_res->workspace; + wl_list_insert(workspace_res->manager->requests.prev, &req->link); } static const struct ext_workspace_handle_v1_interface workspace_impl = { @@ -184,9 +191,9 @@ static const struct ext_workspace_handle_v1_interface workspace_impl = { static void group_handle_create_workspace(struct wl_client *client, struct wl_resource *group_resource, const char *name) { - struct wlr_ext_workspace_group_client_v1 *group = - group_client_from_resource(group_resource); - if (!group) { + struct wlr_ext_workspace_group_v1_resource *group_res = + group_resource_from_resource(group_resource); + if (!group_res) { return; } @@ -195,9 +202,15 @@ static void group_handle_create_workspace(struct wl_client *client, wl_resource_post_no_memory(group_resource); return; } + req->name = strdup(name); + if (!req->name) { + free(req); + wl_resource_post_no_memory(group_resource); + return; + } req->type = WLR_EXT_WORKSPACE_V1_REQUEST_CREATE_WORKSPACE; - req->group = group->group; - wl_list_insert(group->manager->requests.prev, &req->link); + req->group = group_res->group; + wl_list_insert(group_res->manager->requests.prev, &req->link); } static void group_handle_destroy(struct wl_client *client, @@ -210,89 +223,94 @@ static const struct ext_workspace_group_handle_v1_interface group_impl = { .destroy = group_handle_destroy, }; -static void -destroy_workspace_client(struct wlr_ext_workspace_client_v1 *workspace_client) { - wl_list_remove(&workspace_client->link); - wl_resource_set_user_data(workspace_client->resource, NULL); - free(workspace_client); +static void destroy_workspace_resource( + struct wlr_ext_workspace_v1_resource *workspace_res) { + wl_list_remove(&workspace_res->link); + wl_list_remove(&workspace_res->manager_resource_link); + wl_resource_set_user_data(workspace_res->resource, NULL); + free(workspace_res); } static void workspace_resource_destroy(struct wl_resource *resource) { - struct wlr_ext_workspace_client_v1 *workspace_client = - workspace_client_from_resource(resource); - if (workspace_client) { - destroy_workspace_client(workspace_client); + struct wlr_ext_workspace_v1_resource *workspace_res = + workspace_resource_from_resource(resource); + if (workspace_res) { + destroy_workspace_resource(workspace_res); } } -static struct wlr_ext_workspace_client_v1 *create_workspace_client( +static struct wlr_ext_workspace_v1_resource *create_workspace_resource( struct wlr_ext_workspace_handle_v1 *workspace, - struct wlr_ext_workspace_manager_client_v1 *manager_client) { - struct wlr_ext_workspace_client_v1 *workspace_client = - calloc(1, sizeof(*workspace_client)); - if (!workspace_client) { + struct wlr_ext_workspace_manager_v1_resource *manager_res) { + struct wlr_ext_workspace_v1_resource *workspace_res = + calloc(1, sizeof(*workspace_res)); + if (!workspace_res) { return NULL; } - struct wl_client *client = wl_resource_get_client(manager_client->resource); - workspace_client->resource = wl_resource_create( - client, &ext_workspace_handle_v1_interface, - wl_resource_get_version(manager_client->resource), 0); - if (!workspace_client->resource) { - free(workspace_client); + struct wl_client *client = wl_resource_get_client(manager_res->resource); + workspace_res->resource = + wl_resource_create(client, &ext_workspace_handle_v1_interface, + wl_resource_get_version(manager_res->resource), 0); + if (!workspace_res->resource) { + free(workspace_res); return NULL; } - wl_resource_set_implementation(workspace_client->resource, &workspace_impl, - workspace_client, - workspace_resource_destroy); + wl_resource_set_implementation(workspace_res->resource, &workspace_impl, + workspace_res, workspace_resource_destroy); - workspace_client->workspace = workspace; - workspace_client->manager = manager_client; - wl_list_insert(&workspace->clients, &workspace_client->link); + workspace_res->workspace = workspace; + workspace_res->manager = manager_res; + wl_list_insert(&workspace->resources, &workspace_res->link); + wl_list_insert(&manager_res->workspace_resources, + &workspace_res->manager_resource_link); - return workspace_client; + return workspace_res; } static void -destroy_group_client(struct wlr_ext_workspace_group_client_v1 *group_client) { - wl_list_remove(&group_client->link); - wl_resource_set_user_data(group_client->resource, NULL); - free(group_client); +destroy_group_resource(struct wlr_ext_workspace_group_v1_resource *group_res) { + wl_list_remove(&group_res->link); + wl_list_remove(&group_res->manager_resource_link); + wl_resource_set_user_data(group_res->resource, NULL); + free(group_res); } static void group_handle_resource_destroy(struct wl_resource *resource) { - struct wlr_ext_workspace_group_client_v1 *group_client = - group_client_from_resource(resource); - if (group_client) { - destroy_group_client(group_client); + struct wlr_ext_workspace_group_v1_resource *group_res = + group_resource_from_resource(resource); + if (group_res) { + destroy_group_resource(group_res); } } -static struct wlr_ext_workspace_group_client_v1 *create_group_client( +static struct wlr_ext_workspace_group_v1_resource *create_group_resource( struct wlr_ext_workspace_group_handle_v1 *group, - struct wlr_ext_workspace_manager_client_v1 *manager_client) { - struct wlr_ext_workspace_group_client_v1 *group_client = - calloc(1, sizeof(*group_client)); - if (!group_client) { + struct wlr_ext_workspace_manager_v1_resource *manager_res) { + struct wlr_ext_workspace_group_v1_resource *group_res = + calloc(1, sizeof(*group_res)); + if (!group_res) { return NULL; } - struct wl_client *client = wl_resource_get_client(manager_client->resource); - uint32_t version = wl_resource_get_version(manager_client->resource); - group_client->resource = wl_resource_create( + struct wl_client *client = wl_resource_get_client(manager_res->resource); + uint32_t version = wl_resource_get_version(manager_res->resource); + group_res->resource = wl_resource_create( client, &ext_workspace_group_handle_v1_interface, version, 0); - if (group_client->resource == NULL) { - free(group_client); + if (group_res->resource == NULL) { + free(group_res); return NULL; } - wl_resource_set_implementation(group_client->resource, &group_impl, - group_client, group_handle_resource_destroy); + wl_resource_set_implementation(group_res->resource, &group_impl, group_res, + group_handle_resource_destroy); - group_client->group = group; - group_client->manager = manager_client; - wl_list_insert(&group->clients, &group_client->link); + group_res->group = group; + group_res->manager = manager_res; + wl_list_insert(&group->resources, &group_res->link); + wl_list_insert(&manager_res->group_resources, + &group_res->manager_resource_link); - return group_client; + return group_res; } static void destroy_request(struct wlr_ext_workspace_v1_request *req) { @@ -303,18 +321,22 @@ static void destroy_request(struct wlr_ext_workspace_v1_request *req) { static void manager_handle_commit(struct wl_client *client, struct wl_resource *resource) { - struct wlr_ext_workspace_manager_client_v1 *manager = - manager_client_from_resource(resource); - if (!manager) { + struct wlr_ext_workspace_manager_v1_resource *manager_res = + manager_resource_from_resource(resource); + if (!manager_res) { return; } struct wlr_ext_workspace_v1_request *req, *tmp; - wl_list_for_each_safe(req, tmp, &manager->requests, link) { + wl_list_for_each_safe(req, tmp, &manager_res->requests, link) { switch (req->type) { - case WLR_EXT_WORKSPACE_V1_REQUEST_CREATE_WORKSPACE: + case WLR_EXT_WORKSPACE_V1_REQUEST_CREATE_WORKSPACE:; + struct wlr_ext_workspace_group_handle_v1_create_workspace_event + event = { + .name = req->name, + }; wl_signal_emit_mutable(&req->group->events.create_workspace, - req->name); + &event); break; case WLR_EXT_WORKSPACE_V1_REQUEST_ACTIVATE: wl_signal_emit_mutable(&req->workspace->events.activate, NULL); @@ -323,13 +345,11 @@ static void manager_handle_commit(struct wl_client *client, wl_signal_emit_mutable(&req->workspace->events.deactivate, NULL); break; case WLR_EXT_WORKSPACE_V1_REQUEST_ASSIGN: - wl_signal_emit_mutable(&req->workspace->events.assign, &req->group); + wl_signal_emit_mutable(&req->workspace->events.assign, req->group); break; case WLR_EXT_WORKSPACE_V1_REQUEST_REMOVE: wl_signal_emit_mutable(&req->workspace->events.remove, NULL); break; - default: - abort(); } destroy_request(req); } @@ -338,9 +358,9 @@ static void manager_handle_commit(struct wl_client *client, static void handle_idle(void *data) { struct wlr_ext_workspace_manager_v1 *manager = data; - struct wlr_ext_workspace_manager_client_v1 *manager_client; - wl_list_for_each(manager_client, &manager->clients, link) { - ext_workspace_manager_v1_send_done(manager_client->resource); + struct wlr_ext_workspace_manager_v1_resource *manager_res; + wl_list_for_each(manager_res, &manager->resources, link) { + ext_workspace_manager_v1_send_done(manager_res->resource); } manager->idle_source = NULL; } @@ -354,9 +374,9 @@ manager_schedule_done(struct wlr_ext_workspace_manager_v1 *manager) { } static void -workspace_send_details(struct wlr_ext_workspace_client_v1 *workspace_client) { - struct wlr_ext_workspace_handle_v1 *workspace = workspace_client->workspace; - struct wl_resource *resource = workspace_client->resource; +workspace_send_details(struct wlr_ext_workspace_v1_resource *workspace_res) { + struct wlr_ext_workspace_handle_v1 *workspace = workspace_res->workspace; + struct wl_resource *resource = workspace_res->resource; ext_workspace_handle_v1_send_capabilities(resource, workspace->caps); if (workspace->coordinates.size > 0) { @@ -384,29 +404,41 @@ static const struct ext_workspace_manager_v1_interface manager_impl = { .stop = manager_handle_stop, }; -static void destroy_manager_client( - struct wlr_ext_workspace_manager_client_v1 *manager_client) { +static void destroy_manager_resource( + struct wlr_ext_workspace_manager_v1_resource *manager_res) { struct wlr_ext_workspace_v1_request *req, *tmp; - wl_list_for_each_safe(req, tmp, &manager_client->requests, link) { + wl_list_for_each_safe(req, tmp, &manager_res->requests, link) { destroy_request(req); } - wl_list_remove(&manager_client->link); - wl_resource_set_user_data(manager_client->resource, NULL); - free(manager_client); + struct wlr_ext_workspace_v1_resource *workspace_res, *tmp2; + wl_list_for_each_safe(workspace_res, tmp2, + &manager_res->workspace_resources, + manager_resource_link) { + destroy_workspace_resource(workspace_res); + } + struct wlr_ext_workspace_group_v1_resource *group_res, *tmp3; + wl_list_for_each_safe(group_res, tmp3, &manager_res->group_resources, + manager_resource_link) { + destroy_group_resource(group_res); + } + + wl_list_remove(&manager_res->link); + wl_resource_set_user_data(manager_res->resource, NULL); + free(manager_res); } static void manager_resource_destroy(struct wl_resource *resource) { - struct wlr_ext_workspace_manager_client_v1 *manager_client = - manager_client_from_resource(resource); - if (manager_client) { - destroy_manager_client(manager_client); + struct wlr_ext_workspace_manager_v1_resource *manager_res = + manager_resource_from_resource(resource); + if (manager_res) { + destroy_manager_resource(manager_res); } } static void -group_send_details(struct wlr_ext_workspace_group_client_v1 *group_client) { - struct wlr_ext_workspace_group_handle_v1 *group = group_client->group; - struct wl_resource *resource = group_client->resource; +group_send_details(struct wlr_ext_workspace_group_v1_resource *group_res) { + struct wlr_ext_workspace_group_handle_v1 *group = group_res->group; + struct wl_resource *resource = group_res->resource; struct wl_client *client = wl_resource_get_client(resource); ext_workspace_group_handle_v1_send_capabilities(resource, group->caps); @@ -430,65 +462,67 @@ static void manager_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id) { struct wlr_ext_workspace_manager_v1 *manager = data; - struct wlr_ext_workspace_manager_client_v1 *manager_client = - calloc(1, sizeof(*manager_client)); - if (!manager_client) { + struct wlr_ext_workspace_manager_v1_resource *manager_res = + calloc(1, sizeof(*manager_res)); + if (!manager_res) { wl_client_post_no_memory(client); return; } - manager_client->manager = manager; - wl_list_init(&manager_client->requests); - wl_list_insert(&manager->clients, &manager_client->link); + manager_res->manager = manager; + wl_list_init(&manager_res->requests); + wl_list_init(&manager_res->workspace_resources); + wl_list_init(&manager_res->group_resources); - manager_client->resource = wl_resource_create( + manager_res->resource = wl_resource_create( client, &ext_workspace_manager_v1_interface, version, id); - if (!manager_client->resource) { - free(manager_client); + if (!manager_res->resource) { + free(manager_res); wl_client_post_no_memory(client); return; } - wl_resource_set_implementation(manager_client->resource, &manager_impl, - manager_client, manager_resource_destroy); + wl_resource_set_implementation(manager_res->resource, &manager_impl, + manager_res, manager_resource_destroy); + wl_list_insert(&manager->resources, &manager_res->link); struct wlr_ext_workspace_group_handle_v1 *group; wl_list_for_each(group, &manager->groups, link) { - struct wlr_ext_workspace_group_client_v1 *group_client = - create_group_client(group, manager_client); - if (!group_client) { - wl_resource_post_no_memory(manager_client->resource); + struct wlr_ext_workspace_group_v1_resource *group_res = + create_group_resource(group, manager_res); + if (!group_res) { + wl_resource_post_no_memory(manager_res->resource); continue; } - ext_workspace_manager_v1_send_workspace_group(manager_client->resource, - group_client->resource); - group_send_details(group_client); + ext_workspace_manager_v1_send_workspace_group(manager_res->resource, + group_res->resource); + group_send_details(group_res); } struct wlr_ext_workspace_handle_v1 *workspace; wl_list_for_each(workspace, &manager->workspaces, link) { - struct wlr_ext_workspace_client_v1 *workspace_client = - create_workspace_client(workspace, manager_client); - if (!workspace) { - wl_client_post_no_memory(client); + struct wlr_ext_workspace_v1_resource *workspace_res = + create_workspace_resource(workspace, manager_res); + if (!workspace_res) { + wl_resource_post_no_memory(manager_res->resource); continue; } - ext_workspace_manager_v1_send_workspace(manager_client->resource, - workspace_client->resource); - workspace_send_details(workspace_client); + ext_workspace_manager_v1_send_workspace(manager_res->resource, + workspace_res->resource); + workspace_send_details(workspace_res); if (!workspace->group) { continue; } - struct wlr_ext_workspace_group_client_v1 *group_client; - wl_list_for_each(group_client, &workspace->group->clients, link) { - if (group_client->manager == manager_client) { + struct wlr_ext_workspace_group_v1_resource *group_res; + wl_list_for_each(group_res, &workspace->group->resources, link) { + if (group_res->manager == manager_res) { ext_workspace_group_handle_v1_send_workspace_enter( - group_client->resource, workspace_client->resource); + group_res->resource, workspace_res->resource); } } } - manager_schedule_done(manager); + ext_workspace_manager_v1_send_done(manager_res->resource); } static void manager_handle_display_destroy(struct wl_listener *listener, @@ -509,9 +543,9 @@ static void manager_handle_display_destroy(struct wl_listener *listener, wlr_ext_workspace_handle_v1_destroy(workspace); } - struct wlr_ext_workspace_manager_client_v1 *manager_client, *tmp3; - wl_list_for_each_safe(manager_client, tmp3, &manager->clients, link) { - destroy_manager_client(manager_client); + struct wlr_ext_workspace_manager_v1_resource *manager_res, *tmp3; + wl_list_for_each_safe(manager_res, tmp3, &manager->resources, link) { + destroy_manager_resource(manager_res); } if (manager->idle_source) { @@ -548,7 +582,7 @@ wlr_ext_workspace_manager_v1_create(struct wl_display *display, wl_list_init(&manager->groups); wl_list_init(&manager->workspaces); - wl_list_init(&manager->clients); + wl_list_init(&manager->resources); wl_signal_init(&manager->events.destroy); return manager; @@ -566,22 +600,22 @@ wlr_ext_workspace_group_handle_v1_create( group->caps = caps; wl_list_init(&group->outputs); - wl_list_init(&group->clients); + wl_list_init(&group->resources); wl_signal_init(&group->events.create_workspace); wl_signal_init(&group->events.destroy); wl_list_insert(manager->groups.prev, &group->link); - struct wlr_ext_workspace_manager_client_v1 *manager_client; - wl_list_for_each(manager_client, &manager->clients, link) { - struct wlr_ext_workspace_group_client_v1 *group_client = - create_group_client(group, manager_client); - if (!group_client) { + struct wlr_ext_workspace_manager_v1_resource *manager_res; + wl_list_for_each(manager_res, &manager->resources, link) { + struct wlr_ext_workspace_group_v1_resource *group_res = + create_group_resource(group, manager_res); + if (!group_res) { continue; } - ext_workspace_manager_v1_send_workspace_group(manager_client->resource, - group_client->resource); - group_send_details(group_client); + ext_workspace_manager_v1_send_workspace_group(manager_res->resource, + group_res->resource); + group_send_details(group_res); } manager_schedule_done(manager); @@ -594,19 +628,19 @@ workspace_send_group(struct wlr_ext_workspace_handle_v1 *workspace, struct wlr_ext_workspace_group_handle_v1 *group, bool enter) { - struct wlr_ext_workspace_client_v1 *workspace_client; - wl_list_for_each(workspace_client, &workspace->clients, link) { - struct wlr_ext_workspace_group_client_v1 *group_client; - wl_list_for_each(group_client, &group->clients, link) { - if (group_client->manager != workspace_client->manager) { + struct wlr_ext_workspace_v1_resource *workspace_res; + wl_list_for_each(workspace_res, &workspace->resources, link) { + struct wlr_ext_workspace_group_v1_resource *group_res; + wl_list_for_each(group_res, &group->resources, link) { + if (group_res->manager != workspace_res->manager) { continue; } if (enter) { ext_workspace_group_handle_v1_send_workspace_enter( - group_client->resource, workspace_client->resource); + group_res->resource, workspace_res->resource); } else { ext_workspace_group_handle_v1_send_workspace_leave( - group_client->resource, workspace_client->resource); + group_res->resource, workspace_res->resource); } } } @@ -625,10 +659,9 @@ destroy_group_output(struct wlr_ext_workspace_v1_group_output *group_output) { static void group_send_output(struct wlr_ext_workspace_group_handle_v1 *group, struct wlr_output *output, bool enter) { - struct wlr_ext_workspace_group_client_v1 *group_client; - wl_list_for_each(group_client, &group->clients, link) { - struct wl_client *client = - wl_resource_get_client(group_client->resource); + struct wlr_ext_workspace_group_v1_resource *group_res; + wl_list_for_each(group_res, &group->resources, link) { + struct wl_client *client = wl_resource_get_client(group_res->resource); struct wl_resource *output_resource; wl_resource_for_each(output_resource, &output->resources) { @@ -637,10 +670,10 @@ static void group_send_output(struct wlr_ext_workspace_group_handle_v1 *group, } if (enter) { ext_workspace_group_handle_v1_send_output_enter( - group_client->resource, output_resource); + group_res->resource, output_resource); } else { ext_workspace_group_handle_v1_send_output_leave( - group_client->resource, output_resource); + group_res->resource, output_resource); } } } @@ -650,6 +683,10 @@ static void group_send_output(struct wlr_ext_workspace_group_handle_v1 *group, void wlr_ext_workspace_group_handle_v1_destroy( struct wlr_ext_workspace_group_handle_v1 *group) { + if (!group) { + return; + } + wl_signal_emit_mutable(&group->events.destroy, NULL); assert(wl_list_empty(&group->events.create_workspace.listener_list)); @@ -663,16 +700,16 @@ void wlr_ext_workspace_group_handle_v1_destroy( } } - struct wlr_ext_workspace_group_client_v1 *group_client, *tmp; - wl_list_for_each_safe(group_client, tmp, &group->clients, link) { - ext_workspace_group_handle_v1_send_removed(group_client->resource); - destroy_group_client(group_client); + struct wlr_ext_workspace_group_v1_resource *group_res, *tmp; + wl_list_for_each_safe(group_res, tmp, &group->resources, link) { + ext_workspace_group_handle_v1_send_removed(group_res->resource); + destroy_group_resource(group_res); } - struct wlr_ext_workspace_manager_client_v1 *manager_client; - wl_list_for_each(manager_client, &group->manager->clients, link) { + struct wlr_ext_workspace_manager_v1_resource *manager_res; + wl_list_for_each(manager_res, &group->manager->resources, link) { struct wlr_ext_workspace_v1_request *req, *tmp2; - wl_list_for_each_safe(req, tmp2, &manager_client->requests, link) { + wl_list_for_each_safe(req, tmp2, &manager_res->requests, link) { if (req->group == group) { destroy_request(req); } @@ -697,11 +734,11 @@ static void handle_output_bind(struct wl_listener *listener, void *data) { struct wlr_output_event_bind *event = data; struct wl_client *client = wl_resource_get_client(event->resource); - struct wlr_ext_workspace_group_client_v1 *group_client; - wl_list_for_each(group_client, &group_output->group->clients, link) { - if (wl_resource_get_client(group_client->resource) == client) { - ext_workspace_group_handle_v1_send_output_enter( - group_client->resource, event->resource); + struct wlr_ext_workspace_group_v1_resource *group_res; + wl_list_for_each(group_res, &group_output->group->resources, link) { + if (wl_resource_get_client(group_res->resource) == client) { + ext_workspace_group_handle_v1_send_output_enter(group_res->resource, + event->resource); } } @@ -778,11 +815,12 @@ wlr_ext_workspace_handle_v1_create(struct wlr_ext_workspace_manager_v1 *manager, if (id) { workspace->id = strdup(id); if (!workspace->id) { + free(workspace); return NULL; } } - wl_list_init(&workspace->clients); + wl_list_init(&workspace->resources); wl_array_init(&workspace->coordinates); wl_signal_init(&workspace->events.activate); wl_signal_init(&workspace->events.deactivate); @@ -792,16 +830,16 @@ wlr_ext_workspace_handle_v1_create(struct wlr_ext_workspace_manager_v1 *manager, wl_list_insert(&manager->workspaces, &workspace->link); - struct wlr_ext_workspace_manager_client_v1 *manager_client; - wl_list_for_each(manager_client, &manager->clients, link) { - struct wlr_ext_workspace_client_v1 *workspace_client = - create_workspace_client(workspace, manager_client); - if (!workspace_client) { + struct wlr_ext_workspace_manager_v1_resource *manager_res; + wl_list_for_each(manager_res, &manager->resources, link) { + struct wlr_ext_workspace_v1_resource *workspace_res = + create_workspace_resource(workspace, manager_res); + if (!workspace_res) { continue; } - ext_workspace_manager_v1_send_workspace(manager_client->resource, - workspace_client->resource); - workspace_send_details(workspace_client); + ext_workspace_manager_v1_send_workspace(manager_res->resource, + workspace_res->resource); + workspace_send_details(workspace_res); } manager_schedule_done(manager); @@ -811,6 +849,10 @@ wlr_ext_workspace_handle_v1_create(struct wlr_ext_workspace_manager_v1 *manager, void wlr_ext_workspace_handle_v1_destroy( struct wlr_ext_workspace_handle_v1 *workspace) { + if (!workspace) { + return; + } + wl_signal_emit_mutable(&workspace->events.destroy, NULL); assert(wl_list_empty(&workspace->events.activate.listener_list)); @@ -823,16 +865,16 @@ void wlr_ext_workspace_handle_v1_destroy( workspace_send_group(workspace, workspace->group, false); } - struct wlr_ext_workspace_client_v1 *workspace_client, *tmp; - wl_list_for_each_safe(workspace_client, tmp, &workspace->clients, link) { - ext_workspace_handle_v1_send_removed(workspace_client->resource); - destroy_workspace_client(workspace_client); + struct wlr_ext_workspace_v1_resource *workspace_res, *tmp; + wl_list_for_each_safe(workspace_res, tmp, &workspace->resources, link) { + ext_workspace_handle_v1_send_removed(workspace_res->resource); + destroy_workspace_resource(workspace_res); } - struct wlr_ext_workspace_manager_client_v1 *manager_client; - wl_list_for_each(manager_client, &workspace->manager->clients, link) { + struct wlr_ext_workspace_manager_v1_resource *manager_res; + wl_list_for_each(manager_res, &workspace->manager->resources, link) { struct wlr_ext_workspace_v1_request *req, *tmp2; - wl_list_for_each_safe(req, tmp2, &manager_client->requests, link) { + wl_list_for_each_safe(req, tmp2, &manager_res->requests, link) { if (req->workspace == workspace) { destroy_request(req); } @@ -856,7 +898,7 @@ void wlr_ext_workspace_handle_v1_set_group( } if (workspace->group) { - workspace_send_group(workspace, group, false); + workspace_send_group(workspace, workspace->group, false); } workspace->group = group; if (group) { @@ -878,9 +920,9 @@ void wlr_ext_workspace_handle_v1_set_name( return; } - struct wlr_ext_workspace_client_v1 *workspace_client; - wl_list_for_each(workspace_client, &workspace->clients, link) { - ext_workspace_handle_v1_send_name(workspace_client->resource, + struct wlr_ext_workspace_v1_resource *workspace_res; + wl_list_for_each(workspace_res, &workspace->resources, link) { + ext_workspace_handle_v1_send_name(workspace_res->resource, workspace->name); } @@ -905,9 +947,9 @@ void wlr_ext_workspace_handle_v1_set_coordinates( wl_array_init(&workspace->coordinates); wl_array_copy(&workspace->coordinates, coordinates); - struct wlr_ext_workspace_client_v1 *workspace_client; - wl_list_for_each(workspace_client, &workspace->clients, link) { - ext_workspace_handle_v1_send_coordinates(workspace_client->resource, + struct wlr_ext_workspace_v1_resource *workspace_res; + wl_list_for_each(workspace_res, &workspace->resources, link) { + ext_workspace_handle_v1_send_coordinates(workspace_res->resource, &workspace->coordinates); } @@ -927,9 +969,9 @@ static void workspace_set_state(struct wlr_ext_workspace_handle_v1 *workspace, return; } - struct wlr_ext_workspace_client_v1 *workspace_client; - wl_list_for_each(workspace_client, &workspace->clients, link) { - ext_workspace_handle_v1_send_state(workspace_client->resource, + struct wlr_ext_workspace_v1_resource *workspace_res; + wl_list_for_each(workspace_res, &workspace->resources, link) { + ext_workspace_handle_v1_send_state(workspace_res->resource, workspace->state); } diff --git a/src/ext-protocol/wlr_ext_workspace_v1.h b/src/ext-protocol/wlr_ext_workspace_v1.h index e1d285b2..a2a733b3 100644 --- a/src/ext-protocol/wlr_ext_workspace_v1.h +++ b/src/ext-protocol/wlr_ext_workspace_v1.h @@ -2,32 +2,11 @@ // TODO: remove this file // refer: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/5115 -/* - * This an unstable interface of wlroots. No guarantees are made regarding the - * future consistency of this API. - */ -#ifndef WLR_USE_UNSTABLE -#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features" -#endif - -#ifndef WLR_TYPES_WLR_EXT_WORKSPACE_V1_H -#define WLR_TYPES_WLR_EXT_WORKSPACE_V1_H - +#include #include struct wlr_output; -enum wlr_ext_workspace_group_handle_v1_cap { - WLR_EXT_WORKSPACE_GROUP_HANDLE_V1_CAP_CREATE_WORKSPACE = 1 << 0, -}; - -enum wlr_ext_workspace_handle_v1_cap { - WLR_EXT_WORKSPACE_HANDLE_V1_CAP_ACTIVATE = 1 << 0, - WLR_EXT_WORKSPACE_HANDLE_V1_CAP_DEACTIVATE = 1 << 1, - WLR_EXT_WORKSPACE_HANDLE_V1_CAP_REMOVE = 1 << 2, - WLR_EXT_WORKSPACE_HANDLE_V1_CAP_ASSIGN = 1 << 3, -}; - struct wlr_ext_workspace_manager_v1 { struct wl_global *global; struct wl_list groups; // wlr_ext_workspace_group_handle_v1.link @@ -37,24 +16,33 @@ struct wlr_ext_workspace_manager_v1 { struct wl_signal destroy; } events; - struct wl_list clients; // wlr_ext_workspace_manager_client_v1.link - struct wl_event_source *idle_source; - struct wl_event_loop *event_loop; - struct wl_listener display_destroy; + struct { + struct wl_list resources; // wlr_ext_workspace_manager_v1_resource.link + struct wl_event_source *idle_source; + struct wl_event_loop *event_loop; + struct wl_listener display_destroy; + }; +}; + +struct wlr_ext_workspace_group_handle_v1_create_workspace_event { + const char *name; }; struct wlr_ext_workspace_group_handle_v1 { struct wlr_ext_workspace_manager_v1 *manager; - uint32_t caps; // wlr_ext_workspace_group_handle_v1_cap + uint32_t caps; // ext_workspace_group_handle_v1_group_capabilities struct { - struct wl_signal create_workspace; // const char * + struct wl_signal + create_workspace; // wlr_ext_workspace_group_handle_v1_create_workspace_event struct wl_signal destroy; } events; struct wl_list link; // wlr_ext_workspace_manager_v1.groups - struct wl_list outputs; // wlr_ext_workspace_v1_group_output.link - struct wl_list clients; // wlr_ext_workspace_manager_client_v1.link + struct { + struct wl_list outputs; // wlr_ext_workspace_v1_group_output.link + struct wl_list resources; // wlr_ext_workspace_manager_v1_resource.link + }; }; struct wlr_ext_workspace_handle_v1 { @@ -63,7 +51,7 @@ struct wlr_ext_workspace_handle_v1 { char *id; char *name; struct wl_array coordinates; - uint32_t caps; // wlr_ext_workspace_handle_v1_cap + uint32_t caps; // ext_workspace_handle_v1_workspace_capabilities uint32_t state; // ext_workspace_handle_v1_state struct { @@ -74,9 +62,11 @@ struct wlr_ext_workspace_handle_v1 { struct wl_signal destroy; } events; - struct wl_list link; // wlr_ext_workspace_manager_v1.workspaces; + struct wl_list link; // wlr_ext_workspace_manager_v1.workspaces - struct wl_list clients; + struct { + struct wl_list resources; // wlr_ext_workspace_v1_resource.link + }; }; struct wlr_ext_workspace_manager_v1 * @@ -114,5 +104,3 @@ void wlr_ext_workspace_handle_v1_set_urgent( struct wlr_ext_workspace_handle_v1 *workspace, bool enabled); void wlr_ext_workspace_handle_v1_set_hidden( struct wlr_ext_workspace_handle_v1 *workspace, bool enabled); - -#endif diff --git a/src/fetch/client.h b/src/fetch/client.h index 961aac3d..5dc0edd0 100644 --- a/src/fetch/client.h +++ b/src/fetch/client.h @@ -41,10 +41,21 @@ Client *get_client_by_id_or_title(const char *arg_id, const char *arg_title) { continue; } - if (!(appid = client_get_appid(c))) + if (c->swallowedby) { + appid = client_get_appid(c->swallowedby); + title = client_get_title(c->swallowedby); + } else { + appid = client_get_appid(c); + title = client_get_title(c); + } + + if (!appid) { appid = broken; - if (!(title = client_get_title(c))) + } + + if (!title) { title = broken; + } if (arg_id && strncmp(arg_id, "none", 4) == 0) arg_id = NULL; @@ -70,7 +81,7 @@ setclient_coordinate_center(Client *c, struct wlr_box geom, int offsetx, int len = 0; Monitor *m = c->mon ? c->mon : selmon; - unsigned int cbw = check_hit_no_border(c) ? c->bw : 0; + uint32_t cbw = check_hit_no_border(c) ? c->bw : 0; if (!c->no_force_center) { tempbox.x = m->w.x + (m->w.width - geom.width) / 2; @@ -128,8 +139,9 @@ Client *center_tiled_select(Monitor *m) { int dirx, diry; long int distance; wl_list_for_each(c, &clients, link) { - if (c && VISIBLEON(c, m) && ISTILED(c) && client_surface(c)->mapped && - !c->isfloating && !client_is_unmanaged(c)) { + if (c && VISIBLEON(c, m) && ISSCROLLTILED(c) && + client_surface(c)->mapped && !c->isfloating && + !client_is_unmanaged(c)) { dirx = c->geom.x + c->geom.width / 2 - (m->w.x + m->w.width / 2); diry = c->geom.y + c->geom.height / 2 - (m->w.y + m->w.height / 2); distance = dirx * dirx + diry * diry; @@ -142,7 +154,7 @@ Client *center_tiled_select(Monitor *m) { return target_c; } Client *find_client_by_direction(Client *tc, const Arg *arg, bool findfloating, - bool align) { + bool ignore_align) { Client *c = NULL; Client **tempClients = NULL; // 初始化为 NULL int last = -1; @@ -150,7 +162,7 @@ Client *find_client_by_direction(Client *tc, const Arg *arg, bool findfloating, // 第一次遍历,计算客户端数量 wl_list_for_each(c, &clients, link) { if (c && (findfloating || !c->isfloating) && !c->isunglobal && - (focus_cross_monitor || c->mon == selmon) && + (focus_cross_monitor || c->mon == tc->mon) && (c->tags & c->mon->tagset[c->mon->seltags])) { last++; } @@ -171,7 +183,7 @@ Client *find_client_by_direction(Client *tc, const Arg *arg, bool findfloating, last = -1; wl_list_for_each(c, &clients, link) { if (c && (findfloating || !c->isfloating) && !c->isunglobal && - (focus_cross_monitor || c->mon == selmon) && + (focus_cross_monitor || c->mon == tc->mon) && (c->tags & c->mon->tagset[c->mon->seltags])) { last++; tempClients[last] = c; @@ -181,24 +193,29 @@ Client *find_client_by_direction(Client *tc, const Arg *arg, bool findfloating, int sel_x = tc->geom.x; int sel_y = tc->geom.y; long long int distance = LLONG_MAX; + long long int same_monitor_distance = LLONG_MAX; Client *tempFocusClients = NULL; + Client *tempSameMonitorFocusClients = NULL; switch (arg->i) { case UP: - for (int _i = 0; _i <= last; _i++) { - if (tempClients[_i]->geom.y < sel_y && - tempClients[_i]->geom.x == sel_x) { - int dis_x = tempClients[_i]->geom.x - sel_x; - int dis_y = tempClients[_i]->geom.y - sel_y; - long long int tmp_distance = - dis_x * dis_x + dis_y * dis_y; // 计算距离 - if (tmp_distance < distance) { - distance = tmp_distance; - tempFocusClients = tempClients[_i]; + if (!ignore_align) { + for (int _i = 0; _i <= last; _i++) { + if (tempClients[_i]->geom.y < sel_y && + tempClients[_i]->geom.x == sel_x && + tempClients[_i]->mon == tc->mon) { + int dis_x = tempClients[_i]->geom.x - sel_x; + int dis_y = tempClients[_i]->geom.y - sel_y; + long long int tmp_distance = + dis_x * dis_x + dis_y * dis_y; // 计算距离 + if (tmp_distance < distance) { + distance = tmp_distance; + tempFocusClients = tempClients[_i]; + } } } } - if (!tempFocusClients && !align) { + if (!tempFocusClients) { for (int _i = 0; _i <= last; _i++) { if (tempClients[_i]->geom.y < sel_y) { int dis_x = tempClients[_i]->geom.x - sel_x; @@ -209,25 +226,33 @@ Client *find_client_by_direction(Client *tc, const Arg *arg, bool findfloating, distance = tmp_distance; tempFocusClients = tempClients[_i]; } + if (tempClients[_i]->mon == tc->mon && + tmp_distance < same_monitor_distance) { + same_monitor_distance = tmp_distance; + tempSameMonitorFocusClients = tempClients[_i]; + } } } } break; case DOWN: - for (int _i = 0; _i <= last; _i++) { - if (tempClients[_i]->geom.y > sel_y && - tempClients[_i]->geom.x == sel_x) { - int dis_x = tempClients[_i]->geom.x - sel_x; - int dis_y = tempClients[_i]->geom.y - sel_y; - long long int tmp_distance = - dis_x * dis_x + dis_y * dis_y; // 计算距离 - if (tmp_distance < distance) { - distance = tmp_distance; - tempFocusClients = tempClients[_i]; + if (!ignore_align) { + for (int _i = 0; _i <= last; _i++) { + if (tempClients[_i]->geom.y > sel_y && + tempClients[_i]->geom.x == sel_x && + tempClients[_i]->mon == tc->mon) { + int dis_x = tempClients[_i]->geom.x - sel_x; + int dis_y = tempClients[_i]->geom.y - sel_y; + long long int tmp_distance = + dis_x * dis_x + dis_y * dis_y; // 计算距离 + if (tmp_distance < distance) { + distance = tmp_distance; + tempFocusClients = tempClients[_i]; + } } } } - if (!tempFocusClients && !align) { + if (!tempFocusClients) { for (int _i = 0; _i <= last; _i++) { if (tempClients[_i]->geom.y > sel_y) { int dis_x = tempClients[_i]->geom.x - sel_x; @@ -238,25 +263,33 @@ Client *find_client_by_direction(Client *tc, const Arg *arg, bool findfloating, distance = tmp_distance; tempFocusClients = tempClients[_i]; } + if (tempClients[_i]->mon == tc->mon && + tmp_distance < same_monitor_distance) { + same_monitor_distance = tmp_distance; + tempSameMonitorFocusClients = tempClients[_i]; + } } } } break; case LEFT: - for (int _i = 0; _i <= last; _i++) { - if (tempClients[_i]->geom.x < sel_x && - tempClients[_i]->geom.y == sel_y) { - int dis_x = tempClients[_i]->geom.x - sel_x; - int dis_y = tempClients[_i]->geom.y - sel_y; - long long int tmp_distance = - dis_x * dis_x + dis_y * dis_y; // 计算距离 - if (tmp_distance < distance) { - distance = tmp_distance; - tempFocusClients = tempClients[_i]; + if (!ignore_align) { + for (int _i = 0; _i <= last; _i++) { + if (tempClients[_i]->geom.x < sel_x && + tempClients[_i]->geom.y == sel_y && + tempClients[_i]->mon == tc->mon) { + int dis_x = tempClients[_i]->geom.x - sel_x; + int dis_y = tempClients[_i]->geom.y - sel_y; + long long int tmp_distance = + dis_x * dis_x + dis_y * dis_y; // 计算距离 + if (tmp_distance < distance) { + distance = tmp_distance; + tempFocusClients = tempClients[_i]; + } } } } - if (!tempFocusClients && !align) { + if (!tempFocusClients) { for (int _i = 0; _i <= last; _i++) { if (tempClients[_i]->geom.x < sel_x) { int dis_x = tempClients[_i]->geom.x - sel_x; @@ -267,27 +300,21 @@ Client *find_client_by_direction(Client *tc, const Arg *arg, bool findfloating, distance = tmp_distance; tempFocusClients = tempClients[_i]; } + if (tempClients[_i]->mon == tc->mon && + tmp_distance < same_monitor_distance) { + same_monitor_distance = tmp_distance; + tempSameMonitorFocusClients = tempClients[_i]; + } } } } break; case RIGHT: - for (int _i = 0; _i <= last; _i++) { - if (tempClients[_i]->geom.x > sel_x && - tempClients[_i]->geom.y == sel_y) { - int dis_x = tempClients[_i]->geom.x - sel_x; - int dis_y = tempClients[_i]->geom.y - sel_y; - long long int tmp_distance = - dis_x * dis_x + dis_y * dis_y; // 计算距离 - if (tmp_distance < distance) { - distance = tmp_distance; - tempFocusClients = tempClients[_i]; - } - } - } - if (!tempFocusClients && !align) { + if (!ignore_align) { for (int _i = 0; _i <= last; _i++) { - if (tempClients[_i]->geom.x > sel_x) { + if (tempClients[_i]->geom.x > sel_x && + tempClients[_i]->geom.y == sel_y && + tempClients[_i]->mon == tc->mon) { int dis_x = tempClients[_i]->geom.x - sel_x; int dis_y = tempClients[_i]->geom.y - sel_y; long long int tmp_distance = @@ -299,11 +326,34 @@ Client *find_client_by_direction(Client *tc, const Arg *arg, bool findfloating, } } } + if (!tempFocusClients) { + for (int _i = 0; _i <= last; _i++) { + if (tempClients[_i]->geom.x > sel_x) { + int dis_x = tempClients[_i]->geom.x - sel_x; + int dis_y = tempClients[_i]->geom.y - sel_y; + long long int tmp_distance = + dis_x * dis_x + dis_y * dis_y; // 计算距离 + if (tmp_distance < distance) { + distance = tmp_distance; + tempFocusClients = tempClients[_i]; + } + if (tempClients[_i]->mon == tc->mon && + tmp_distance < same_monitor_distance) { + same_monitor_distance = tmp_distance; + tempSameMonitorFocusClients = tempClients[_i]; + } + } + } + } break; } free(tempClients); // 释放内存 - return tempFocusClients; + if (tempSameMonitorFocusClients) { + return tempSameMonitorFocusClients; + } else { + return tempFocusClients; + } } Client *direction_select(const Arg *arg) { @@ -313,12 +363,13 @@ Client *direction_select(const Arg *arg) { if (!tc) return NULL; - if (tc && (tc->isfullscreen || tc->ismaxmizescreen)) { - // 不支持全屏窗口的焦点切换 + if (tc && (tc->isfullscreen || tc->ismaximizescreen) && + (!is_scroller_layout(selmon) || tc->isfloating)) { return NULL; } - return find_client_by_direction(tc, arg, true, false); + return find_client_by_direction( + tc, arg, true, is_scroller_layout(selmon) && !selmon->isoverview); } /* We probably should change the name of this, it sounds like @@ -336,17 +387,47 @@ Client *focustop(Monitor *m) { } Client *get_next_stack_client(Client *c, bool reverse) { + if (!c || !c->mon) + return NULL; + Client *next = NULL; if (reverse) { wl_list_for_each_reverse(next, &c->link, link) { - if (VISIBLEON(next, c->mon) && next != c) + if (&next->link == &clients) + continue; /* wrap past the sentinel node */ + + if (next != c && next->mon && VISIBLEON(next, c->mon)) return next; } } else { wl_list_for_each(next, &c->link, link) { - if (VISIBLEON(next, c->mon) && next != c) + if (&next->link == &clients) + continue; /* wrap past the sentinel node */ + + if (next != c && next->mon && VISIBLEON(next, c->mon)) return next; } } return NULL; } + +float *get_border_color(Client *c) { + + if (c->mon != selmon) { + return bordercolor; + } else if (c->isurgent) { + return urgentcolor; + } else if (c->is_in_scratchpad && selmon && c == selmon->sel) { + return scratchpadcolor; + } else if (c->isglobal && selmon && c == selmon->sel) { + return globalcolor; + } else if (c->isoverlay && selmon && c == selmon->sel) { + return overlaycolor; + } else if (c->ismaximizescreen && selmon && c == selmon->sel) { + return maximizescreencolor; + } else if (selmon && c == selmon->sel) { + return focuscolor; + } else { + return bordercolor; + } +} \ No newline at end of file diff --git a/src/fetch/common.h b/src/fetch/common.h index afa49f64..c96ee31b 100644 --- a/src/fetch/common.h +++ b/src/fetch/common.h @@ -1,5 +1,5 @@ pid_t getparentprocess(pid_t p) { - unsigned int v = 0; + uint32_t v = 0; FILE *f; char buf[256]; @@ -26,29 +26,15 @@ int isdescprocess(pid_t p, pid_t c) { return (int)c; } -char *get_autostart_path(char *autostart_path, unsigned int buf_size) { - const char *mangoconfig = getenv("MANGOCONFIG"); +void get_layout_abbr(char *abbr, const char *full_name) { + // 清空输出缓冲区 + abbr[0] = '\0'; - if (mangoconfig && mangoconfig[0] != '\0') { - snprintf(autostart_path, buf_size, "%s/autostart.sh", mangoconfig); - } else { - const char *homedir = getenv("HOME"); - if (!homedir) { - fprintf(stderr, "Error: HOME environment variable not set.\n"); - return NULL; - } - snprintf(autostart_path, buf_size, "%s/.config/mango/autostart.sh", - homedir); - } - - return autostart_path; -} - -const char *get_layout_abbr(const char *full_name) { // 1. 尝试在映射表中查找 for (int i = 0; layout_mappings[i].full_name != NULL; i++) { if (strcmp(full_name, layout_mappings[i].full_name) == 0) { - return layout_mappings[i].abbr; + strcpy(abbr, layout_mappings[i].abbr); + return; } } @@ -56,48 +42,39 @@ const char *get_layout_abbr(const char *full_name) { const char *open = strrchr(full_name, '('); const char *close = strrchr(full_name, ')'); if (open && close && close > open) { - unsigned int len = close - open - 1; + uint32_t len = close - open - 1; if (len > 0 && len <= 4) { - char *abbr = malloc(len + 1); - if (abbr) { - // 提取并转换为小写 - for (unsigned int j = 0; j < len; j++) { - abbr[j] = tolower(open[j + 1]); - } - abbr[len] = '\0'; - return abbr; + // 提取并转换为小写 + for (uint32_t j = 0; j < len; j++) { + abbr[j] = tolower(open[j + 1]); } + abbr[len] = '\0'; + return; } } // 3. 提取前2-3个字母并转换为小写 - char *abbr = malloc(4); - if (abbr) { - unsigned int j = 0; - for (unsigned int i = 0; full_name[i] != '\0' && j < 3; i++) { - if (isalpha(full_name[i])) { - abbr[j++] = tolower(full_name[i]); - } + uint32_t j = 0; + for (uint32_t i = 0; full_name[i] != '\0' && j < 3; i++) { + if (isalpha(full_name[i])) { + abbr[j++] = tolower(full_name[i]); } - abbr[j] = '\0'; + } + abbr[j] = '\0'; - // 确保至少2个字符 - if (j >= 2) - return abbr; - free(abbr); + // 确保至少2个字符 + if (j >= 2) { + return; } // 4. 回退方案:使用首字母小写 - char *fallback = malloc(3); - if (fallback) { - fallback[0] = tolower(full_name[0]); - fallback[1] = full_name[1] ? tolower(full_name[1]) : '\0'; - fallback[2] = '\0'; - return fallback; + if (j == 1) { + abbr[1] = full_name[1] ? tolower(full_name[1]) : '\0'; + abbr[2] = '\0'; + } else { + // 5. 最终回退:返回 "xx" + strcpy(abbr, "xx"); } - - // 5. 最终回退:返回 "xx" - return strdup("xx"); } void xytonode(double x, double y, struct wlr_surface **psurface, Client **pc, @@ -120,6 +97,10 @@ void xytonode(double x, double y, struct wlr_surface **psurface, Client **pc, surface = wlr_scene_surface_try_from_buffer( wlr_scene_buffer_from_node(node)) ->surface; + else if (node->type == WLR_SCENE_NODE_RECT) { + surface = NULL; + break; + } /* start from the topmost layer, find a sureface that can be focused by pointer, diff --git a/src/fetch/monitor.h b/src/fetch/monitor.h index d55e9ab6..47a5b824 100644 --- a/src/fetch/monitor.h +++ b/src/fetch/monitor.h @@ -26,9 +26,9 @@ bool is_scroller_layout(Monitor *m) { return false; } -unsigned int get_tag_status(unsigned int tag, Monitor *m) { +uint32_t get_tag_status(uint32_t tag, Monitor *m) { Client *c = NULL; - unsigned int status = 0; + uint32_t status = 0; wl_list_for_each(c, &clients, link) { if (c->mon == m && c->tags & 1 << (tag - 1) & TAGMASK) { if (c->isurgent) { @@ -41,8 +41,8 @@ unsigned int get_tag_status(unsigned int tag, Monitor *m) { return status; } -unsigned int get_tags_first_tag_num(unsigned int source_tags) { - unsigned int i, tag; +uint32_t get_tags_first_tag_num(uint32_t source_tags) { + uint32_t i, tag; tag = 0; if (!source_tags) { @@ -63,8 +63,8 @@ unsigned int get_tags_first_tag_num(unsigned int source_tags) { } // 获取tags中最前面的tag的tagmask -unsigned int get_tags_first_tag(unsigned int source_tags) { - unsigned int i, tag; +uint32_t get_tags_first_tag(uint32_t source_tags) { + uint32_t i, tag; tag = 0; if (!source_tags) { diff --git a/src/layout/arrange.h b/src/layout/arrange.h index 18d6b15e..a7805aff 100644 --- a/src/layout/arrange.h +++ b/src/layout/arrange.h @@ -5,7 +5,7 @@ void set_size_per(Monitor *m, Client *c) { if (VISIBLEON(fc, m) && ISTILED(fc) && fc != c) { c->master_mfact_per = fc->master_mfact_per; c->master_inner_per = fc->master_inner_per; - c->stack_innder_per = fc->stack_innder_per; + c->stack_inner_per = fc->stack_inner_per; found = true; break; } @@ -14,12 +14,12 @@ void set_size_per(Monitor *m, Client *c) { if (!found) { c->master_mfact_per = m->pertag->mfacts[m->pertag->curtag]; c->master_inner_per = 1.0f; - c->stack_innder_per = 1.0f; + c->stack_inner_per = 1.0f; } } void resize_tile_master_horizontal(Client *grabc, bool isdrag, int offsetx, - int offsety, unsigned int time, int type) { + int offsety, uint32_t time, int type) { Client *tc = NULL; float delta_x, delta_y; Client *next = NULL; @@ -70,7 +70,7 @@ void resize_tile_master_horizontal(Client *grabc, bool isdrag, int offsetx, // 记录初始状态 grabc->old_master_mfact_per = grabc->master_mfact_per; grabc->old_master_inner_per = grabc->master_inner_per; - grabc->old_stack_innder_per = grabc->stack_innder_per; + grabc->old_stack_inner_per = grabc->stack_inner_per; grabc->cursor_in_upper_half = cursor->y < grabc->geom.y + grabc->geom.height / 2; grabc->cursor_in_left_half = @@ -86,7 +86,7 @@ void resize_tile_master_horizontal(Client *grabc, bool isdrag, int offsetx, } else { grabc->old_master_mfact_per = grabc->master_mfact_per; grabc->old_master_inner_per = grabc->master_inner_per; - grabc->old_stack_innder_per = grabc->stack_innder_per; + grabc->old_stack_inner_per = grabc->stack_inner_per; grabc->drag_begin_geom = grabc->geom; grabc->cursor_in_upper_half = true; grabc->cursor_in_left_half = false; @@ -100,7 +100,7 @@ void resize_tile_master_horizontal(Client *grabc, bool isdrag, int offsetx, } else { delta_x = (float)(offsetx) * (1 - grabc->old_master_mfact_per) / grabc->drag_begin_geom.width; - delta_y = (float)(offsety) * (grabc->old_stack_innder_per) / + delta_y = (float)(offsety) * (grabc->old_stack_inner_per) / grabc->drag_begin_geom.height; } bool moving_up; @@ -182,12 +182,12 @@ void resize_tile_master_horizontal(Client *grabc, bool isdrag, int offsetx, // 直接设置新的比例,基于初始值 + 变化量 float new_master_mfact_per = grabc->old_master_mfact_per + delta_x; float new_master_inner_per = grabc->old_master_inner_per + delta_y; - float new_stack_innder_per = grabc->old_stack_innder_per + delta_y; + float new_stack_inner_per = grabc->old_stack_inner_per + delta_y; // 应用限制,确保比例在合理范围内 new_master_mfact_per = fmaxf(0.1f, fminf(0.9f, new_master_mfact_per)); new_master_inner_per = fmaxf(0.1f, fminf(0.9f, new_master_inner_per)); - new_stack_innder_per = fmaxf(0.1f, fminf(0.9f, new_stack_innder_per)); + new_stack_inner_per = fmaxf(0.1f, fminf(0.9f, new_stack_inner_per)); // 应用到所有平铺窗口 wl_list_for_each(tc, &clients, link) { @@ -197,7 +197,7 @@ void resize_tile_master_horizontal(Client *grabc, bool isdrag, int offsetx, } grabc->master_inner_per = new_master_inner_per; - grabc->stack_innder_per = new_stack_innder_per; + grabc->stack_inner_per = new_stack_inner_per; if (!isdrag) { arrange(grabc->mon, false); @@ -213,7 +213,7 @@ void resize_tile_master_horizontal(Client *grabc, bool isdrag, int offsetx, } void resize_tile_master_vertical(Client *grabc, bool isdrag, int offsetx, - int offsety, unsigned int time, int type) { + int offsety, uint32_t time, int type) { Client *tc = NULL; float delta_x, delta_y; Client *next = NULL; @@ -250,7 +250,7 @@ void resize_tile_master_vertical(Client *grabc, bool isdrag, int offsetx, // 记录初始状态 grabc->old_master_mfact_per = grabc->master_mfact_per; grabc->old_master_inner_per = grabc->master_inner_per; - grabc->old_stack_innder_per = grabc->stack_innder_per; + grabc->old_stack_inner_per = grabc->stack_inner_per; grabc->cursor_in_upper_half = cursor->y < grabc->geom.y + grabc->geom.height / 2; grabc->cursor_in_left_half = @@ -267,7 +267,7 @@ void resize_tile_master_vertical(Client *grabc, bool isdrag, int offsetx, } else { grabc->old_master_mfact_per = grabc->master_mfact_per; grabc->old_master_inner_per = grabc->master_inner_per; - grabc->old_stack_innder_per = grabc->stack_innder_per; + grabc->old_stack_inner_per = grabc->stack_inner_per; grabc->drag_begin_geom = grabc->geom; grabc->cursor_in_upper_half = true; grabc->cursor_in_left_half = false; @@ -280,7 +280,7 @@ void resize_tile_master_vertical(Client *grabc, bool isdrag, int offsetx, delta_y = (float)(offsety) * (grabc->old_master_mfact_per) / grabc->drag_begin_geom.height; } else { - delta_x = (float)(offsetx) * (grabc->old_stack_innder_per) / + delta_x = (float)(offsetx) * (grabc->old_stack_inner_per) / grabc->drag_begin_geom.width; delta_y = (float)(offsety) * (1 - grabc->old_master_mfact_per) / grabc->drag_begin_geom.height; @@ -338,13 +338,13 @@ void resize_tile_master_vertical(Client *grabc, bool isdrag, int offsetx, delta_y; // 垂直:delta_y调整主区域高度 float new_master_inner_per = grabc->old_master_inner_per + delta_x; // 垂直:delta_x调整主区域内部宽度 - float new_stack_innder_per = grabc->old_stack_innder_per + - delta_x; // 垂直:delta_x调整栈区域内部宽度 + float new_stack_inner_per = grabc->old_stack_inner_per + + delta_x; // 垂直:delta_x调整栈区域内部宽度 // 应用限制,确保比例在合理范围内 new_master_mfact_per = fmaxf(0.1f, fminf(0.9f, new_master_mfact_per)); new_master_inner_per = fmaxf(0.1f, fminf(0.9f, new_master_inner_per)); - new_stack_innder_per = fmaxf(0.1f, fminf(0.9f, new_stack_innder_per)); + new_stack_inner_per = fmaxf(0.1f, fminf(0.9f, new_stack_inner_per)); // 应用到所有平铺窗口 wl_list_for_each(tc, &clients, link) { @@ -354,7 +354,7 @@ void resize_tile_master_vertical(Client *grabc, bool isdrag, int offsetx, } grabc->master_inner_per = new_master_inner_per; - grabc->stack_innder_per = new_stack_innder_per; + grabc->stack_inner_per = new_stack_inner_per; if (!isdrag) { arrange(grabc->mon, false); @@ -370,10 +370,14 @@ void resize_tile_master_vertical(Client *grabc, bool isdrag, int offsetx, } void resize_tile_scroller(Client *grabc, bool isdrag, int offsetx, int offsety, - unsigned int time, bool isvertical) { + uint32_t time, bool isvertical) { float delta_x, delta_y; float new_scroller_proportion; + if (grabc && grabc->mon->visible_tiling_clients == 1 && + !scroller_ignore_proportion_single) + return; + if (!start_drag_window && isdrag) { drag_begin_cursorx = cursor->x; drag_begin_cursory = cursor->y; @@ -398,7 +402,7 @@ void resize_tile_scroller(Client *grabc, bool isdrag, int offsetx, int offsety, } else { grabc->old_master_mfact_per = grabc->master_mfact_per; grabc->old_master_inner_per = grabc->master_inner_per; - grabc->old_stack_innder_per = grabc->stack_innder_per; + grabc->old_stack_inner_per = grabc->stack_inner_per; grabc->drag_begin_geom = grabc->geom; grabc->old_scroller_pproportion = grabc->scroller_proportion; grabc->cursor_in_upper_half = false; @@ -470,15 +474,19 @@ void resize_tile_scroller(Client *grabc, bool isdrag, int offsetx, int offsety, } void resize_tile_client(Client *grabc, bool isdrag, int offsetx, int offsety, - unsigned int time) { + uint32_t time) { - if (!grabc || grabc->isfullscreen || grabc->ismaxmizescreen) + if (!grabc || grabc->isfullscreen || grabc->ismaximizescreen) + return; + + if (grabc->mon->isoverview) return; const Layout *current_layout = grabc->mon->pertag->ltidxs[grabc->mon->pertag->curtag]; if (current_layout->id == TILE || current_layout->id == DECK || - current_layout->id == CENTER_TILE || current_layout->id == RIGHT_TILE + current_layout->id == CENTER_TILE || current_layout->id == RIGHT_TILE || + (current_layout->id == TGMIX && grabc->mon->visible_tiling_clients <= 3) ) { resize_tile_master_horizontal(grabc, isdrag, offsetx, offsety, time, @@ -502,27 +510,25 @@ void reset_size_per_mon(Monitor *m, int tile_cilent_num, int stack_num) { Client *c = NULL; int i = 0; - unsigned int stack_index = 0; - unsigned int nmasters = m->pertag->nmasters[m->pertag->curtag]; + uint32_t stack_index = 0; + uint32_t nmasters = m->pertag->nmasters[m->pertag->curtag]; if (m->pertag->ltidxs[m->pertag->curtag]->id != CENTER_TILE) { wl_list_for_each(c, &clients, link) { if (VISIBLEON(c, m) && ISTILED(c)) { - - if (total_master_inner_percent <= 0.0) - return; - if (i < m->pertag->nmasters[m->pertag->curtag]) { + if (total_master_inner_percent > 0.0 && i < nmasters) { c->ismaster = true; - c->stack_innder_per = stack_num ? 1.0f / stack_num : 1.0f; + c->stack_inner_per = stack_num ? 1.0f / stack_num : 1.0f; c->master_inner_per = c->master_inner_per / total_master_inner_percent; } else { c->ismaster = false; - c->master_inner_per = 1.0f / master_num; - c->stack_innder_per = + c->master_inner_per = + master_num > 0 ? 1.0f / master_num : 1.0f; + c->stack_inner_per = total_stack_hight_percent - ? c->stack_innder_per / total_stack_hight_percent + ? c->stack_inner_per / total_stack_hight_percent : 1.0f; } i++; @@ -531,17 +537,14 @@ void reset_size_per_mon(Monitor *m, int tile_cilent_num, } else { wl_list_for_each(c, &clients, link) { if (VISIBLEON(c, m) && ISTILED(c)) { - - if (total_master_inner_percent <= 0.0) - return; - if (i < m->pertag->nmasters[m->pertag->curtag]) { + if (total_master_inner_percent > 0.0 && i < nmasters) { c->ismaster = true; if ((stack_index % 2) ^ (tile_cilent_num % 2 == 0)) { - c->stack_innder_per = + c->stack_inner_per = stack_num > 1 ? 1.0f / ((stack_num - 1) / 2) : 1.0f; } else { - c->stack_innder_per = + c->stack_inner_per = stack_num > 1 ? 2.0f / stack_num : 1.0f; } @@ -551,17 +554,18 @@ void reset_size_per_mon(Monitor *m, int tile_cilent_num, stack_index = i - nmasters; c->ismaster = false; - c->master_inner_per = 1.0f / master_num; + c->master_inner_per = + master_num > 0 ? 1.0f / master_num : 1.0f; if ((stack_index % 2) ^ (tile_cilent_num % 2 == 0)) { - c->stack_innder_per = + c->stack_inner_per = total_right_stack_hight_percent - ? c->stack_innder_per / + ? c->stack_inner_per / total_right_stack_hight_percent : 1.0f; } else { - c->stack_innder_per = + c->stack_inner_per = total_left_stack_hight_percent - ? c->stack_innder_per / + ? c->stack_inner_per / total_left_stack_hight_percent : 1.0f; } @@ -575,7 +579,7 @@ void reset_size_per_mon(Monitor *m, int tile_cilent_num, void // 17 arrange(Monitor *m, bool want_animation) { Client *c = NULL; - double total_stack_innder_percent = 0; + double total_stack_inner_percent = 0; double total_master_inner_percent = 0; double total_right_stack_hight_percent = 0; double total_left_stack_hight_percent = 0; @@ -592,6 +596,7 @@ arrange(Monitor *m, bool want_animation) { return; m->visible_clients = 0; m->visible_tiling_clients = 0; + m->visible_scroll_tiling_clients = 0; wl_list_for_each(c, &clients, link) { @@ -602,10 +607,16 @@ arrange(Monitor *m, bool want_animation) { } if (VISIBLEON(c, m)) { - m->visible_clients++; + if (!c->isunglobal) + m->visible_clients++; + if (ISTILED(c)) { m->visible_tiling_clients++; } + + if (ISSCROLLTILED(c)) { + m->visible_scroll_tiling_clients++; + } } } @@ -619,22 +630,22 @@ arrange(Monitor *m, bool want_animation) { if (VISIBLEON(c, m)) { if (ISTILED(c)) { - if (i < m->pertag->nmasters[m->pertag->curtag]) { + if (i < nmasters) { master_num++; total_master_inner_percent += c->master_inner_per; } else { stack_num++; - total_stack_innder_percent += c->stack_innder_per; + total_stack_inner_percent += c->stack_inner_per; stack_index = i - nmasters; if ((stack_index % 2) ^ (m->visible_tiling_clients % 2 == 0)) { c->isleftstack = false; total_right_stack_hight_percent += - c->stack_innder_per; + c->stack_inner_per; } else { c->isleftstack = true; total_left_stack_hight_percent += - c->stack_innder_per; + c->stack_inner_per; } } @@ -647,15 +658,15 @@ arrange(Monitor *m, bool want_animation) { } } - if (c->mon == m && c->ismaxmizescreen && !c->animation.tagouted && + if (c->mon == m && c->ismaximizescreen && !c->animation.tagouted && !c->animation.tagouting && VISIBLEON(c, m)) { - reset_maxmizescreen_size(c); + reset_maximizescreen_size(c); } } reset_size_per_mon( m, m->visible_tiling_clients, total_left_stack_hight_percent, - total_right_stack_hight_percent, total_stack_innder_percent, + total_right_stack_hight_percent, total_stack_inner_percent, total_master_inner_percent, master_num, stack_num); if (m->isoverview) { @@ -668,4 +679,6 @@ arrange(Monitor *m, bool want_animation) { motionnotify(0, NULL, 0, 0, 0, 0); checkidleinhibitor(NULL); } + + printstatus(); } diff --git a/src/layout/horizontal.h b/src/layout/horizontal.h index 3bebd3de..a9d6248a 100644 --- a/src/layout/horizontal.h +++ b/src/layout/horizontal.h @@ -1,9 +1,9 @@ // 网格布局窗口大小和位置计算 void grid(Monitor *m) { - unsigned int i, n; - unsigned int cx, cy, cw, ch; - unsigned int dx; - unsigned int cols, rows, overcols; + uint32_t i, n; + uint32_t cx, cy, cw, ch; + uint32_t dx; + uint32_t cols, rows, overcols; Client *c = NULL; n = 0; int target_gappo = enablegaps ? m->isoverview ? overviewgappo : gappoh : 0; @@ -23,13 +23,8 @@ void grid(Monitor *m) { if (c->mon != m) continue; - c->bw = m->visible_tiling_clients == 1 && no_border_when_single && - smartgaps - ? 0 - : borderpx; if (VISIBLEON(c, m) && !c->isunglobal && - ((m->isoverview && !client_should_ignore_focus(c)) || - ISTILED(c))) { + ((m->isoverview && !client_is_x11_popup(c)) || ISTILED(c))) { cw = (m->w.width - 2 * target_gappo) * single_width_ratio; ch = (m->w.height - 2 * target_gappo) * single_height_ratio; c->geom.x = m->w.x + (m->w.width - cw) / 2; @@ -50,13 +45,8 @@ void grid(Monitor *m) { if (c->mon != m) continue; - c->bw = m->visible_tiling_clients == 1 && no_border_when_single && - smartgaps - ? 0 - : borderpx; if (VISIBLEON(c, m) && !c->isunglobal && - ((m->isoverview && !client_should_ignore_focus(c)) || - ISTILED(c))) { + ((m->isoverview && !client_is_x11_popup(c)) || ISTILED(c))) { if (i == 0) { c->geom.x = m->w.x + target_gappo; c->geom.y = m->w.y + (m->w.height - ch) / 2 + target_gappo; @@ -101,12 +91,9 @@ void grid(Monitor *m) { if (c->mon != m) continue; - c->bw = - m->visible_tiling_clients == 1 && no_border_when_single && smartgaps - ? 0 - : borderpx; + if (VISIBLEON(c, m) && !c->isunglobal && - ((m->isoverview && !client_should_ignore_focus(c)) || ISTILED(c))) { + ((m->isoverview && !client_is_x11_popup(c)) || ISTILED(c))) { cx = m->w.x + (i % cols) * (cw + target_gappi); cy = m->w.y + (i / cols) * (ch + target_gappi); if (overcols && i >= n - overcols) { @@ -123,15 +110,15 @@ void grid(Monitor *m) { } void deck(Monitor *m) { - unsigned int mw, my; + uint32_t mw, my; int i, n = 0; Client *c = NULL; Client *fc = NULL; float mfact; - unsigned int cur_gappih = enablegaps ? m->gappih : 0; - unsigned int cur_gappoh = enablegaps ? m->gappoh : 0; - unsigned int cur_gappov = enablegaps ? m->gappov : 0; + uint32_t cur_gappih = enablegaps ? m->gappih : 0; + uint32_t cur_gappoh = enablegaps ? m->gappoh : 0; + uint32_t cur_gappov = enablegaps ? m->gappov : 0; cur_gappih = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappih; cur_gappoh = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappoh; @@ -191,27 +178,62 @@ void deck(Monitor *m) { } } +void horizontal_scroll_adjust_fullandmax(Client *c, + struct wlr_box *target_geom) { + Monitor *m = c->mon; + uint32_t cur_gappih = enablegaps ? m->gappih : 0; + uint32_t cur_gappoh = enablegaps ? m->gappoh : 0; + uint32_t cur_gappov = enablegaps ? m->gappov : 0; + + cur_gappih = + smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappih; + cur_gappoh = + smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappoh; + cur_gappov = + smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappov; + + if (c->isfullscreen) { + target_geom->height = m->m.height; + target_geom->width = m->m.width; + target_geom->y = m->m.y; + return; + } + + if (c->ismaximizescreen) { + target_geom->height = m->w.height - 2 * cur_gappov; + target_geom->width = m->w.width - 2 * cur_gappoh; + target_geom->y = m->w.y + cur_gappov; + return; + } + + target_geom->height = m->w.height - 2 * cur_gappov; + target_geom->y = m->w.y + (m->w.height - target_geom->height) / 2; +} + // 滚动布局 void scroller(Monitor *m) { - unsigned int i, n, j; + uint32_t i, n, j; + float single_proportion = 1.0; Client *c = NULL, *root_client = NULL; Client **tempClients = NULL; // 初始化为 NULL struct wlr_box target_geom; int focus_client_index = 0; bool need_scroller = false; - unsigned int cur_gappih = enablegaps ? m->gappih : 0; - unsigned int cur_gappoh = enablegaps ? m->gappoh : 0; - unsigned int cur_gappov = enablegaps ? m->gappov : 0; + uint32_t cur_gappih = enablegaps ? m->gappih : 0; + uint32_t cur_gappoh = enablegaps ? m->gappoh : 0; + uint32_t cur_gappov = enablegaps ? m->gappov : 0; - cur_gappih = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappih; - cur_gappoh = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappoh; - cur_gappov = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappov; + cur_gappih = + smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappih; + cur_gappoh = + smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappoh; + cur_gappov = + smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappov; - unsigned int max_client_width = - m->w.width - 2 * scroller_structs - cur_gappih; + uint32_t max_client_width = m->w.width - 2 * scroller_structs - cur_gappih; - n = m->visible_tiling_clients; + n = m->visible_scroll_tiling_clients; if (n == 0) { return; // 没有需要处理的客户端,直接返回 @@ -227,17 +249,22 @@ void scroller(Monitor *m) { // 第二次遍历,填充 tempClients j = 0; wl_list_for_each(c, &clients, link) { - if (VISIBLEON(c, m) && ISTILED(c)) { + if (VISIBLEON(c, m) && ISSCROLLTILED(c)) { tempClients[j] = c; j++; } } - if (n == 1) { + if (n == 1 && !scroller_ignore_proportion_single && + !tempClients[0]->isfullscreen && !tempClients[0]->ismaximizescreen) { c = tempClients[0]; + + single_proportion = c->scroller_proportion_single > 0.0f + ? c->scroller_proportion_single + : scroller_default_proportion_single; + target_geom.height = m->w.height - 2 * cur_gappov; - target_geom.width = - (m->w.width - 2 * cur_gappoh) * scroller_default_proportion_single; + target_geom.width = (m->w.width - 2 * cur_gappoh) * single_proportion; target_geom.x = m->w.x + (m->w.width - target_geom.width) / 2; target_geom.y = m->w.y + (m->w.height - target_geom.height) / 2; resize(c, target_geom, 0); @@ -245,11 +272,10 @@ void scroller(Monitor *m) { return; } - if (m->sel && !client_is_unmanaged(m->sel) && !m->sel->isfloating && - !m->sel->ismaxmizescreen && !m->sel->isfullscreen) { + if (m->sel && !client_is_unmanaged(m->sel) && ISSCROLLTILED(m->sel)) { root_client = m->sel; - } else if (m->prevsel && ISTILED(m->prevsel) && VISIBLEON(m->prevsel, m) && - !client_is_unmanaged(m->prevsel)) { + } else if (m->prevsel && ISSCROLLTILED(m->prevsel) && + VISIBLEON(m->prevsel, m) && !client_is_unmanaged(m->prevsel)) { root_client = m->prevsel; } else { root_client = center_tiled_select(m); @@ -263,8 +289,7 @@ void scroller(Monitor *m) { for (i = 0; i < n; i++) { c = tempClients[i]; if (root_client == c) { - if (!c->is_pending_open_animation && - c->geom.x >= m->w.x + scroller_structs && + if (c->geom.x >= m->w.x + scroller_structs && c->geom.x + c->geom.width <= m->w.x + m->w.width - scroller_structs) { need_scroller = false; @@ -276,17 +301,28 @@ void scroller(Monitor *m) { } } + if (n == 1 && scroller_ignore_proportion_single) { + need_scroller = true; + } + if (start_drag_window) need_scroller = false; target_geom.height = m->w.height - 2 * cur_gappov; target_geom.width = max_client_width * c->scroller_proportion; target_geom.y = m->w.y + (m->w.height - target_geom.height) / 2; - - if (need_scroller) { + horizontal_scroll_adjust_fullandmax(tempClients[focus_client_index], + &target_geom); + if (tempClients[focus_client_index]->isfullscreen) { + target_geom.x = m->m.x; + resize(tempClients[focus_client_index], target_geom, 0); + } else if (tempClients[focus_client_index]->ismaximizescreen) { + target_geom.x = m->w.x + cur_gappoh; + resize(tempClients[focus_client_index], target_geom, 0); + } else if (need_scroller) { if (scroller_focus_center || ((!m->prevsel || - (ISTILED(m->prevsel) && + (ISSCROLLTILED(m->prevsel) && (m->prevsel->scroller_proportion * max_client_width) + (root_client->scroller_proportion * max_client_width) > m->w.width - 2 * scroller_structs - cur_gappih)) && @@ -309,14 +345,17 @@ void scroller(Monitor *m) { for (i = 1; i <= focus_client_index; i++) { c = tempClients[focus_client_index - i]; target_geom.width = max_client_width * c->scroller_proportion; + horizontal_scroll_adjust_fullandmax(c, &target_geom); target_geom.x = tempClients[focus_client_index - i + 1]->geom.x - cur_gappih - target_geom.width; + resize(c, target_geom, 0); } for (i = 1; i < n - focus_client_index; i++) { c = tempClients[focus_client_index + i]; target_geom.width = max_client_width * c->scroller_proportion; + horizontal_scroll_adjust_fullandmax(c, &target_geom); target_geom.x = tempClients[focus_client_index + i - 1]->geom.x + cur_gappih + tempClients[focus_client_index + i - 1]->geom.width; @@ -327,7 +366,7 @@ void scroller(Monitor *m) { } void center_tile(Monitor *m) { - unsigned int i, n = 0, h, r, ie = enablegaps, mw, mx, my, oty, ety, tw; + uint32_t i, n = 0, h, r, ie = enablegaps, mw, mx, my, oty, ety, tw; Client *c = NULL; Client *fc = NULL; double mfact = 0; @@ -336,6 +375,8 @@ void center_tile(Monitor *m) { n = m->visible_tiling_clients; master_num = m->pertag->nmasters[m->pertag->curtag]; + master_num = n > master_num ? master_num : n; + stack_num = n - master_num; if (n == 0) @@ -348,10 +389,10 @@ void center_tile(Monitor *m) { } // 间隙参数处理 - unsigned int cur_gappiv = enablegaps ? m->gappiv : 0; // 内部垂直间隙 - unsigned int cur_gappih = enablegaps ? m->gappih : 0; // 内部水平间隙 - unsigned int cur_gappov = enablegaps ? m->gappov : 0; // 外部垂直间隙 - unsigned int cur_gappoh = enablegaps ? m->gappoh : 0; // 外部水平间隙 + uint32_t cur_gappiv = enablegaps ? m->gappiv : 0; // 内部垂直间隙 + uint32_t cur_gappih = enablegaps ? m->gappih : 0; // 内部水平间隙 + uint32_t cur_gappov = enablegaps ? m->gappov : 0; // 外部垂直间隙 + uint32_t cur_gappoh = enablegaps ? m->gappoh : 0; // 外部水平间隙 // 智能间隙处理 cur_gappiv = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappiv; @@ -359,7 +400,7 @@ void center_tile(Monitor *m) { cur_gappov = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappov; cur_gappoh = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappoh; - unsigned int nmasters = m->pertag->nmasters[m->pertag->curtag]; + uint32_t nmasters = m->pertag->nmasters[m->pertag->curtag]; mfact = fc->master_mfact_per > 0.0f ? fc->master_mfact_per : m->pertag->mfacts[m->pertag->curtag]; @@ -372,6 +413,19 @@ void center_tile(Monitor *m) { // 判断是否需要主区域铺满 int should_overspread = center_master_overspread && (n <= nmasters); + uint32_t master_surplus_height = + (m->w.height - 2 * cur_gappov - cur_gappiv * ie * (master_num - 1)); + float master_surplus_ratio = 1.0; + + uint32_t slave_left_surplus_height = + (m->w.height - 2 * cur_gappov - cur_gappiv * ie * (stack_num / 2 - 1)); + float slave_left_surplus_ratio = 1.0; + + uint32_t slave_right_surplus_height = + (m->w.height - 2 * cur_gappov - + cur_gappiv * ie * ((stack_num + 1) / 2 - 1)); + float slave_right_surplus_ratio = 1.0; + if (n > nmasters || !should_overspread) { // 计算主区域宽度(居中模式) mw = nmasters ? (m->w.width - 2 * cur_gappoh - cur_gappih * ie) * mfact @@ -416,9 +470,11 @@ void center_tile(Monitor *m) { // 主区域窗口 r = MIN(n, nmasters) - i; if (c->master_inner_per > 0.0f) { - h = (m->w.height - 2 * cur_gappov - - cur_gappiv * ie * (master_num - 1)) * - c->master_inner_per; + h = master_surplus_height * c->master_inner_per / + master_surplus_ratio; + master_surplus_height = master_surplus_height - h; + master_surplus_ratio = + master_surplus_ratio - c->master_inner_per; c->master_mfact_per = mfact; } else { h = (m->w.height - my - cur_gappov - @@ -438,22 +494,22 @@ void center_tile(Monitor *m) { my += c->geom.height + cur_gappiv * ie; } else { // 堆叠区域窗口 - unsigned int stack_index = i - nmasters; + uint32_t stack_index = i - nmasters; if (n - nmasters == 1) { // 单个堆叠窗口 r = n - i; - if (c->stack_innder_per > 0.0f) { + if (c->stack_inner_per > 0.0f) { h = (m->w.height - 2 * cur_gappov - cur_gappiv * ie * (stack_num - 1)) * - c->stack_innder_per; + c->stack_inner_per; c->master_mfact_per = mfact; } else { h = (m->w.height - ety - cur_gappov - cur_gappiv * ie * (r - 1)) / r; - c->stack_innder_per = h / (m->w.height - ety - cur_gappov - - cur_gappiv * ie * (r - 1)); + c->stack_inner_per = h / (m->w.height - ety - cur_gappov - + cur_gappiv * ie * (r - 1)); c->master_mfact_per = mfact; } @@ -479,16 +535,19 @@ void center_tile(Monitor *m) { if ((stack_index % 2) ^ (n % 2 == 0)) { // 右侧堆叠窗口 - if (c->stack_innder_per > 0.0f) { - h = (m->w.height - 2 * cur_gappov - - cur_gappiv * ie * ((stack_num + 1) / 2 - 1)) * - c->stack_innder_per; + if (c->stack_inner_per > 0.0f) { + h = slave_right_surplus_height * c->stack_inner_per / + slave_right_surplus_ratio; + slave_right_surplus_height = + slave_right_surplus_height - h; + slave_right_surplus_ratio = + slave_right_surplus_ratio - c->stack_inner_per; c->master_mfact_per = mfact; } else { h = (m->w.height - ety - cur_gappov - cur_gappiv * ie * (r - 1)) / r; - c->stack_innder_per = + c->stack_inner_per = h / (m->w.height - ety - cur_gappov - cur_gappiv * ie * (r - 1)); c->master_mfact_per = mfact; @@ -505,16 +564,19 @@ void center_tile(Monitor *m) { ety += c->geom.height + cur_gappiv * ie; } else { // 左侧堆叠窗口 - if (c->stack_innder_per > 0.0f) { - h = (m->w.height - 2 * cur_gappov - - cur_gappiv * ie * (stack_num / 2 - 1)) * - c->stack_innder_per; + if (c->stack_inner_per > 0.0f) { + h = slave_left_surplus_height * c->stack_inner_per / + slave_left_surplus_ratio; + slave_left_surplus_height = + slave_left_surplus_height - h; + slave_left_surplus_ratio = + slave_left_surplus_ratio - c->stack_inner_per; c->master_mfact_per = mfact; } else { h = (m->w.height - oty - cur_gappov - cur_gappiv * ie * (r - 1)) / r; - c->stack_innder_per = + c->stack_inner_per = h / (m->w.height - oty - cur_gappov - cur_gappiv * ie * (r - 1)); c->master_mfact_per = mfact; @@ -536,7 +598,7 @@ void center_tile(Monitor *m) { } void tile(Monitor *m) { - unsigned int i, n = 0, h, r, ie = enablegaps, mw, my, ty; + uint32_t i, n = 0, h, r, ie = enablegaps, mw, my, ty; Client *c = NULL; Client *fc = NULL; double mfact = 0; @@ -545,15 +607,16 @@ void tile(Monitor *m) { n = m->visible_tiling_clients; master_num = m->pertag->nmasters[m->pertag->curtag]; + master_num = n > master_num ? master_num : n; stack_num = n - master_num; if (n == 0) return; - unsigned int cur_gappiv = enablegaps ? m->gappiv : 0; - unsigned int cur_gappih = enablegaps ? m->gappih : 0; - unsigned int cur_gappov = enablegaps ? m->gappov : 0; - unsigned int cur_gappoh = enablegaps ? m->gappoh : 0; + uint32_t cur_gappiv = enablegaps ? m->gappiv : 0; + uint32_t cur_gappih = enablegaps ? m->gappih : 0; + uint32_t cur_gappov = enablegaps ? m->gappov : 0; + uint32_t cur_gappoh = enablegaps ? m->gappoh : 0; cur_gappiv = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappiv; cur_gappih = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappih; @@ -577,15 +640,26 @@ void tile(Monitor *m) { mw = m->w.width - 2 * cur_gappoh + cur_gappih * ie; i = 0; my = ty = cur_gappov; + + uint32_t master_surplus_height = + (m->w.height - 2 * cur_gappov - cur_gappiv * ie * (master_num - 1)); + float master_surplus_ratio = 1.0; + + uint32_t slave_surplus_height = + (m->w.height - 2 * cur_gappov - cur_gappiv * ie * (stack_num - 1)); + float slave_surplus_ratio = 1.0; + wl_list_for_each(c, &clients, link) { if (!VISIBLEON(c, m) || !ISTILED(c)) continue; if (i < m->pertag->nmasters[m->pertag->curtag]) { r = MIN(n, m->pertag->nmasters[m->pertag->curtag]) - i; if (c->master_inner_per > 0.0f) { - h = (m->w.height - 2 * cur_gappov - - cur_gappiv * ie * (master_num - 1)) * - c->master_inner_per; + h = master_surplus_height * c->master_inner_per / + master_surplus_ratio; + master_surplus_height = master_surplus_height - h; + master_surplus_ratio = + master_surplus_ratio - c->master_inner_per; c->master_mfact_per = mfact; } else { h = (m->w.height - my - cur_gappov - @@ -604,21 +678,22 @@ void tile(Monitor *m) { my += c->geom.height + cur_gappiv * ie; } else { r = n - i; - if (c->stack_innder_per > 0.0f) { - h = (m->w.height - 2 * cur_gappov - - cur_gappiv * ie * (stack_num - 1)) * - c->stack_innder_per; + if (c->stack_inner_per > 0.0f) { + h = slave_surplus_height * c->stack_inner_per / + slave_surplus_ratio; + slave_surplus_height = slave_surplus_height - h; + slave_surplus_ratio = slave_surplus_ratio - c->stack_inner_per; c->master_mfact_per = mfact; } else { h = (m->w.height - ty - cur_gappov - cur_gappiv * ie * (r - 1)) / r; - c->stack_innder_per = h / (m->w.height - ty - cur_gappov - - cur_gappiv * ie * (r - 1)); + c->stack_inner_per = h / (m->w.height - ty - cur_gappov - + cur_gappiv * ie * (r - 1)); c->master_mfact_per = mfact; } - // wlr_log(WLR_ERROR, "stack_innder_per: %f", c->stack_innder_per); + // wlr_log(WLR_ERROR, "stack_inner_per: %f", c->stack_inner_per); resize(c, (struct wlr_box){.x = m->w.x + mw + cur_gappoh, @@ -633,7 +708,7 @@ void tile(Monitor *m) { } void right_tile(Monitor *m) { - unsigned int i, n = 0, h, r, ie = enablegaps, mw, my, ty; + uint32_t i, n = 0, h, r, ie = enablegaps, mw, my, ty; Client *c = NULL; Client *fc = NULL; double mfact = 0; @@ -642,15 +717,16 @@ void right_tile(Monitor *m) { n = m->visible_tiling_clients; master_num = m->pertag->nmasters[m->pertag->curtag]; + master_num = n > master_num ? master_num : n; stack_num = n - master_num; if (n == 0) return; - unsigned int cur_gappiv = enablegaps ? m->gappiv : 0; - unsigned int cur_gappih = enablegaps ? m->gappih : 0; - unsigned int cur_gappov = enablegaps ? m->gappov : 0; - unsigned int cur_gappoh = enablegaps ? m->gappoh : 0; + uint32_t cur_gappiv = enablegaps ? m->gappiv : 0; + uint32_t cur_gappih = enablegaps ? m->gappih : 0; + uint32_t cur_gappov = enablegaps ? m->gappov : 0; + uint32_t cur_gappoh = enablegaps ? m->gappoh : 0; cur_gappiv = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappiv; cur_gappih = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappih; @@ -674,15 +750,26 @@ void right_tile(Monitor *m) { mw = m->w.width - 2 * cur_gappoh + cur_gappih * ie; i = 0; my = ty = cur_gappov; + + uint32_t master_surplus_height = + (m->w.height - 2 * cur_gappov - cur_gappiv * ie * (master_num - 1)); + float master_surplus_ratio = 1.0; + + uint32_t slave_surplus_height = + (m->w.height - 2 * cur_gappov - cur_gappiv * ie * (stack_num - 1)); + float slave_surplus_ratio = 1.0; + wl_list_for_each(c, &clients, link) { if (!VISIBLEON(c, m) || !ISTILED(c)) continue; if (i < m->pertag->nmasters[m->pertag->curtag]) { r = MIN(n, m->pertag->nmasters[m->pertag->curtag]) - i; if (c->master_inner_per > 0.0f) { - h = (m->w.height - 2 * cur_gappov - - cur_gappiv * ie * (master_num - 1)) * - c->master_inner_per; + h = master_surplus_height * c->master_inner_per / + master_surplus_ratio; + master_surplus_height = master_surplus_height - h; + master_surplus_ratio = + master_surplus_ratio - c->master_inner_per; c->master_mfact_per = mfact; } else { h = (m->w.height - my - cur_gappov - @@ -702,21 +789,22 @@ void right_tile(Monitor *m) { my += c->geom.height + cur_gappiv * ie; } else { r = n - i; - if (c->stack_innder_per > 0.0f) { - h = (m->w.height - 2 * cur_gappov - - cur_gappiv * ie * (stack_num - 1)) * - c->stack_innder_per; + if (c->stack_inner_per > 0.0f) { + h = slave_surplus_height * c->stack_inner_per / + slave_surplus_ratio; + slave_surplus_height = slave_surplus_height - h; + slave_surplus_ratio = slave_surplus_ratio - c->stack_inner_per; c->master_mfact_per = mfact; } else { h = (m->w.height - ty - cur_gappov - cur_gappiv * ie * (r - 1)) / r; - c->stack_innder_per = h / (m->w.height - ty - cur_gappov - - cur_gappiv * ie * (r - 1)); + c->stack_inner_per = h / (m->w.height - ty - cur_gappov - + cur_gappiv * ie * (r - 1)); c->master_mfact_per = mfact; } - // wlr_log(WLR_ERROR, "stack_innder_per: %f", c->stack_innder_per); + // wlr_log(WLR_ERROR, "stack_inner_per: %f", c->stack_inner_per); resize(c, (struct wlr_box){.x = m->w.x + cur_gappoh, @@ -735,8 +823,8 @@ monocle(Monitor *m) { Client *c = NULL; struct wlr_box geom; - unsigned int cur_gappov = enablegaps ? m->gappov : 0; - unsigned int cur_gappoh = enablegaps ? m->gappoh : 0; + uint32_t cur_gappov = enablegaps ? m->gappov : 0; + uint32_t cur_gappoh = enablegaps ? m->gappoh : 0; cur_gappoh = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappoh; cur_gappov = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappov; @@ -752,4 +840,15 @@ monocle(Monitor *m) { } if ((c = focustop(m))) wlr_scene_node_raise_to_top(&c->scene->node); +} + +void tgmix(Monitor *m) { + uint32_t n = m->visible_tiling_clients; + if (n <= 3) { + tile(m); + return; + } else { + grid(m); + return; + } } \ No newline at end of file diff --git a/src/layout/layout.h b/src/layout/layout.h index 62a3227d..169ab119 100644 --- a/src/layout/layout.h +++ b/src/layout/layout.h @@ -11,6 +11,7 @@ static void vertical_overview(Monitor *m); static void vertical_grid(Monitor *m); static void vertical_scroller(Monitor *m); static void vertical_deck(Monitor *mon); +static void tgmix(Monitor *m); /* layout(s) */ Layout overviewlayout = {"󰃇", overview, "overview"}; @@ -27,6 +28,7 @@ enum { VERTICAL_GRID, VERTICAL_DECK, RIGHT_TILE, + TGMIX, }; Layout layouts[] = { @@ -44,4 +46,5 @@ Layout layouts[] = { {"VT", vertical_tile, "vertical_tile", VERTICAL_TILE}, // 垂直平铺布局 {"VG", vertical_grid, "vertical_grid", VERTICAL_GRID}, // 垂直格子布局 {"VK", vertical_deck, "vertical_deck", VERTICAL_DECK}, // 垂直卡片布局 + {"TG", tgmix, "tgmix", TGMIX}, // 混合布局 }; \ No newline at end of file diff --git a/src/layout/vertical.h b/src/layout/vertical.h index 3cddcba8..da6a1279 100644 --- a/src/layout/vertical.h +++ b/src/layout/vertical.h @@ -1,5 +1,5 @@ void vertical_tile(Monitor *m) { - unsigned int i, n = 0, w, r, ie = enablegaps, mh, mx, tx; + uint32_t i, n = 0, w, r, ie = enablegaps, mh, mx, tx; Client *c = NULL; Client *fc = NULL; double mfact = 0; @@ -8,15 +8,16 @@ void vertical_tile(Monitor *m) { n = m->visible_tiling_clients; master_num = m->pertag->nmasters[m->pertag->curtag]; + master_num = n > master_num ? master_num : n; stack_num = n - master_num; if (n == 0) return; - unsigned int cur_gapih = enablegaps ? m->gappih : 0; - unsigned int cur_gapiv = enablegaps ? m->gappiv : 0; - unsigned int cur_gapoh = enablegaps ? m->gappoh : 0; - unsigned int cur_gapov = enablegaps ? m->gappov : 0; + uint32_t cur_gapih = enablegaps ? m->gappih : 0; + uint32_t cur_gapiv = enablegaps ? m->gappiv : 0; + uint32_t cur_gapoh = enablegaps ? m->gappoh : 0; + uint32_t cur_gapov = enablegaps ? m->gappov : 0; cur_gapih = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gapih; cur_gapiv = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gapiv; @@ -39,16 +40,27 @@ void vertical_tile(Monitor *m) { mh = m->w.height - 2 * cur_gapov + cur_gapiv * ie; i = 0; - mx = tx = cur_gapih; + mx = tx = cur_gapoh; + + uint32_t master_surplus_width = + (m->w.width - 2 * cur_gapoh - cur_gapih * ie * (master_num - 1)); + float master_surplus_ratio = 1.0; + + uint32_t slave_surplus_width = + (m->w.width - 2 * cur_gapoh - cur_gapih * ie * (stack_num - 1)); + float slave_surplus_ratio = 1.0; + wl_list_for_each(c, &clients, link) { if (!VISIBLEON(c, m) || !ISTILED(c)) continue; if (i < m->pertag->nmasters[m->pertag->curtag]) { r = MIN(n, m->pertag->nmasters[m->pertag->curtag]) - i; if (c->master_inner_per > 0.0f) { - w = (m->w.width - 2 * cur_gapih - - cur_gapih * ie * (master_num - 1)) * - c->master_inner_per; + w = master_surplus_width * c->master_inner_per / + master_surplus_ratio; + master_surplus_width = master_surplus_width - w; + master_surplus_ratio = + master_surplus_ratio - c->master_inner_per; c->master_mfact_per = mfact; } else { w = (m->w.width - mx - cur_gapih - cur_gapih * ie * (r - 1)) / @@ -66,16 +78,17 @@ void vertical_tile(Monitor *m) { mx += c->geom.width + cur_gapih * ie; } else { r = n - i; - if (c->stack_innder_per > 0.0f) { - w = (m->w.width - 2 * cur_gapih - - cur_gapih * ie * (stack_num - 1)) * - c->stack_innder_per; + if (c->stack_inner_per > 0.0f) { + w = slave_surplus_width * c->stack_inner_per / + slave_surplus_ratio; + slave_surplus_width = slave_surplus_width - w; + slave_surplus_ratio = slave_surplus_ratio - c->stack_inner_per; c->master_mfact_per = mfact; } else { w = (m->w.width - tx - cur_gapih - cur_gapih * ie * (r - 1)) / r; - c->stack_innder_per = w / (m->w.width - tx - cur_gapih - - cur_gapih * ie * (r - 1)); + c->stack_inner_per = w / (m->w.width - tx - cur_gapih - + cur_gapih * ie * (r - 1)); c->master_mfact_per = mfact; } @@ -92,15 +105,15 @@ void vertical_tile(Monitor *m) { } void vertical_deck(Monitor *m) { - unsigned int mh, mx; + uint32_t mh, mx; int i, n = 0; Client *c = NULL; Client *fc = NULL; float mfact; - unsigned int cur_gappiv = enablegaps ? m->gappiv : 0; - unsigned int cur_gappoh = enablegaps ? m->gappoh : 0; - unsigned int cur_gappov = enablegaps ? m->gappov : 0; + uint32_t cur_gappiv = enablegaps ? m->gappiv : 0; + uint32_t cur_gappoh = enablegaps ? m->gappoh : 0; + uint32_t cur_gappov = enablegaps ? m->gappov : 0; cur_gappiv = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappiv; cur_gappoh = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappoh; @@ -155,25 +168,62 @@ void vertical_deck(Monitor *m) { } } +void vertical_scroll_adjust_fullandmax(Client *c, struct wlr_box *target_geom) { + Monitor *m = c->mon; + uint32_t cur_gappiv = enablegaps ? m->gappiv : 0; + uint32_t cur_gappov = enablegaps ? m->gappov : 0; + uint32_t cur_gappoh = enablegaps ? m->gappoh : 0; + + cur_gappiv = + smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappiv; + cur_gappov = + smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappov; + cur_gappoh = + smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappoh; + + if (c->isfullscreen) { + target_geom->width = m->m.width; + target_geom->height = m->m.height; + target_geom->x = m->m.x; + return; + } + + if (c->ismaximizescreen) { + target_geom->width = m->w.width - 2 * cur_gappoh; + target_geom->height = m->w.height - 2 * cur_gappov; + target_geom->x = m->w.x + cur_gappoh; + return; + } + + target_geom->width = m->w.width - 2 * cur_gappoh; + target_geom->x = m->w.x + (m->w.width - target_geom->width) / 2; +} + +// 竖屏滚动布局 void vertical_scroller(Monitor *m) { - unsigned int i, n, j; + uint32_t i, n, j; + float single_proportion = 1.0; + Client *c = NULL, *root_client = NULL; Client **tempClients = NULL; struct wlr_box target_geom; int focus_client_index = 0; bool need_scroller = false; - unsigned int cur_gappiv = enablegaps ? m->gappiv : 0; - unsigned int cur_gappov = enablegaps ? m->gappov : 0; - unsigned int cur_gappoh = enablegaps ? m->gappoh : 0; + uint32_t cur_gappiv = enablegaps ? m->gappiv : 0; + uint32_t cur_gappov = enablegaps ? m->gappov : 0; + uint32_t cur_gappoh = enablegaps ? m->gappoh : 0; - cur_gappiv = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappiv; - cur_gappov = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappov; - cur_gappoh = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappoh; + cur_gappiv = + smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappiv; + cur_gappov = + smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappov; + cur_gappoh = + smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappoh; - unsigned int max_client_height = + uint32_t max_client_height = m->w.height - 2 * scroller_structs - cur_gappiv; - n = m->visible_tiling_clients; + n = m->visible_scroll_tiling_clients; if (n == 0) { return; @@ -186,29 +236,33 @@ void vertical_scroller(Monitor *m) { j = 0; wl_list_for_each(c, &clients, link) { - if (VISIBLEON(c, m) && ISTILED(c)) { + if (VISIBLEON(c, m) && ISSCROLLTILED(c)) { tempClients[j] = c; j++; } } - if (n == 1) { + if (n == 1 && !scroller_ignore_proportion_single && + !tempClients[0]->isfullscreen && !tempClients[0]->ismaximizescreen) { c = tempClients[0]; + + single_proportion = c->scroller_proportion_single > 0.0f + ? c->scroller_proportion_single + : scroller_default_proportion_single; + target_geom.width = m->w.width - 2 * cur_gappoh; - target_geom.height = - (m->w.height - 2 * cur_gappov) * scroller_default_proportion_single; - target_geom.x = m->w.x + (m->w.width - target_geom.width) / 2; + target_geom.height = (m->w.height - 2 * cur_gappov) * single_proportion; target_geom.y = m->w.y + (m->w.height - target_geom.height) / 2; + target_geom.x = m->w.x + (m->w.width - target_geom.width) / 2; resize(c, target_geom, 0); free(tempClients); return; } - if (m->sel && !client_is_unmanaged(m->sel) && !m->sel->isfloating && - !m->sel->ismaxmizescreen && !m->sel->isfullscreen) { + if (m->sel && !client_is_unmanaged(m->sel) && ISSCROLLTILED(m->sel)) { root_client = m->sel; - } else if (m->prevsel && ISTILED(m->prevsel) && VISIBLEON(m->prevsel, m) && - !client_is_unmanaged(m->prevsel)) { + } else if (m->prevsel && ISSCROLLTILED(m->prevsel) && + VISIBLEON(m->prevsel, m) && !client_is_unmanaged(m->prevsel)) { root_client = m->prevsel; } else { root_client = center_tiled_select(m); @@ -222,8 +276,7 @@ void vertical_scroller(Monitor *m) { for (i = 0; i < n; i++) { c = tempClients[i]; if (root_client == c) { - if (!c->is_pending_open_animation && - c->geom.y >= m->w.y + scroller_structs && + if (c->geom.y >= m->w.y + scroller_structs && c->geom.y + c->geom.height <= m->w.y + m->w.height - scroller_structs) { need_scroller = false; @@ -235,14 +288,29 @@ void vertical_scroller(Monitor *m) { } } + if (n == 1 && scroller_ignore_proportion_single) { + need_scroller = true; + } + + if (start_drag_window) + need_scroller = false; + target_geom.width = m->w.width - 2 * cur_gappoh; target_geom.height = max_client_height * c->scroller_proportion; target_geom.x = m->w.x + (m->w.width - target_geom.width) / 2; + vertical_scroll_adjust_fullandmax(tempClients[focus_client_index], + &target_geom); - if (need_scroller) { + if (tempClients[focus_client_index]->isfullscreen) { + target_geom.y = m->m.y; + resize(tempClients[focus_client_index], target_geom, 0); + } else if (tempClients[focus_client_index]->ismaximizescreen) { + target_geom.y = m->w.y + cur_gappov; + resize(tempClients[focus_client_index], target_geom, 0); + } else if (need_scroller) { if (scroller_focus_center || ((!m->prevsel || - (ISTILED(m->prevsel) && + (ISSCROLLTILED(m->prevsel) && (m->prevsel->scroller_proportion * max_client_height) + (root_client->scroller_proportion * max_client_height) > m->w.height - 2 * scroller_structs - cur_gappiv)) && @@ -265,14 +333,17 @@ void vertical_scroller(Monitor *m) { for (i = 1; i <= focus_client_index; i++) { c = tempClients[focus_client_index - i]; target_geom.height = max_client_height * c->scroller_proportion; + vertical_scroll_adjust_fullandmax(c, &target_geom); target_geom.y = tempClients[focus_client_index - i + 1]->geom.y - cur_gappiv - target_geom.height; + resize(c, target_geom, 0); } for (i = 1; i < n - focus_client_index; i++) { c = tempClients[focus_client_index + i]; target_geom.height = max_client_height * c->scroller_proportion; + vertical_scroll_adjust_fullandmax(c, &target_geom); target_geom.y = tempClients[focus_client_index + i - 1]->geom.y + cur_gappiv + tempClients[focus_client_index + i - 1]->geom.height; @@ -283,10 +354,10 @@ void vertical_scroller(Monitor *m) { } void vertical_grid(Monitor *m) { - unsigned int i, n; - unsigned int cx, cy, cw, ch; - unsigned int dy; - unsigned int rows, cols, overrows; + uint32_t i, n; + uint32_t cx, cy, cw, ch; + uint32_t dy; + uint32_t rows, cols, overrows; Client *c = NULL; int target_gappo = enablegaps ? m->isoverview ? overviewgappo : gappov : 0; int target_gappi = enablegaps ? m->isoverview ? overviewgappi : gappiv : 0; @@ -305,13 +376,8 @@ void vertical_grid(Monitor *m) { if (c->mon != m) continue; - c->bw = m->visible_tiling_clients == 1 && no_border_when_single && - smartgaps - ? 0 - : borderpx; if (VISIBLEON(c, m) && !c->isunglobal && - ((m->isoverview && !client_should_ignore_focus(c)) || - ISTILED(c))) { + ((m->isoverview && !client_is_x11_popup(c)) || ISTILED(c))) { ch = (m->w.height - 2 * target_gappo) * single_height_ratio; cw = (m->w.width - 2 * target_gappo) * single_width_ratio; c->geom.x = m->w.x + (m->w.width - cw) / 2; @@ -333,13 +399,8 @@ void vertical_grid(Monitor *m) { if (c->mon != m) continue; - c->bw = m->visible_tiling_clients == 1 && no_border_when_single && - smartgaps - ? 0 - : borderpx; if (VISIBLEON(c, m) && !c->isunglobal && - ((m->isoverview && !client_should_ignore_focus(c)) || - ISTILED(c))) { + ((m->isoverview && !client_is_x11_popup(c)) || ISTILED(c))) { if (i == 0) { c->geom.x = m->w.x + (m->w.width - cw) / 2 + target_gappo; c->geom.y = m->w.y + target_gappo; @@ -380,12 +441,8 @@ void vertical_grid(Monitor *m) { if (c->mon != m) continue; - c->bw = - m->visible_tiling_clients == 1 && no_border_when_single && smartgaps - ? 0 - : borderpx; if (VISIBLEON(c, m) && !c->isunglobal && - ((m->isoverview && !client_should_ignore_focus(c)) || ISTILED(c))) { + ((m->isoverview && !client_is_x11_popup(c)) || ISTILED(c))) { cx = m->w.x + (i / rows) * (cw + target_gappi); cy = m->w.y + (i % rows) * (ch + target_gappi); if (overrows && i >= n - overrows) { diff --git a/src/mango.c b/src/mango.c index 225b76aa..f993e17c 100644 --- a/src/mango.c +++ b/src/mango.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -47,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -103,17 +105,20 @@ A->geom.x + A->geom.width <= A->mon->m.x + A->mon->m.width && \ A->geom.y + A->geom.height <= A->mon->m.y + A->mon->m.height) #define ISTILED(A) \ - (A && !(A)->isfloating && !(A)->isminied && !(A)->iskilling && \ - !(A)->ismaxmizescreen && !(A)->isfullscreen) + (A && !(A)->isfloating && !(A)->isminimized && !(A)->iskilling && \ + !(A)->ismaximizescreen && !(A)->isfullscreen && !(A)->isunglobal) +#define ISSCROLLTILED(A) \ + (A && !(A)->isfloating && !(A)->isminimized && !(A)->iskilling && \ + !(A)->isunglobal) #define VISIBLEON(C, M) \ - ((M) && (C)->mon == (M) && ((C)->tags & (M)->tagset[(M)->seltags])) + ((C) && (M) && (C)->mon == (M) && ((C)->tags & (M)->tagset[(M)->seltags])) #define LENGTH(X) (sizeof X / sizeof X[0]) #define END(A) ((A) + LENGTH(A)) #define TAGMASK ((1 << LENGTH(tags)) - 1) #define LISTEN(E, L, H) wl_signal_add((E), ((L)->notify = (H), (L))) #define ISFULLSCREEN(A) \ - ((A)->isfullscreen || (A)->ismaxmizescreen || \ - (A)->overview_ismaxmizescreenbak || (A)->overview_isfullscreenbak) + ((A)->isfullscreen || (A)->ismaximizescreen || \ + (A)->overview_ismaximizescreenbak || (A)->overview_isfullscreenbak) #define LISTEN_STATIC(E, H) \ do { \ struct wl_listener *_l = ecalloc(1, sizeof(*_l)); \ @@ -163,9 +168,43 @@ enum { }; /* EWMH atoms */ #endif enum { UP, DOWN, LEFT, RIGHT, UNDIR }; /* smartmovewin */ -enum { NONE, OPEN, MOVE, CLOSE, TAG }; +enum { NONE, OPEN, MOVE, CLOSE, TAG, FOCUS, OPAFADEIN, OPAFADEOUT }; enum { UNFOLD, FOLD, INVALIDFOLD }; enum { PREV, NEXT }; +enum { STATE_UNSPECIFIED = 0, STATE_ENABLED, STATE_DISABLED }; + +enum tearing_mode { + TEARING_DISABLED = 0, + TEARING_ENABLED, + TEARING_FULLSCREEN_ONLY, +}; + +enum seat_config_shortcuts_inhibit { + SHORTCUTS_INHIBIT_DISABLE, + SHORTCUTS_INHIBIT_ENABLE, +}; + +// 事件掩码枚举 +enum print_event_type { + PRINT_ACTIVE = 1 << 0, + PRINT_TAG = 1 << 1, + PRINT_LAYOUT = 1 << 2, + PRINT_TITLE = 1 << 3, + PRINT_APPID = 1 << 4, + PRINT_LAYOUT_SYMBOL = 1 << 5, + PRINT_FULLSCREEN = 1 << 6, + PRINT_FLOATING = 1 << 7, + PRINT_X = 1 << 8, + PRINT_Y = 1 << 9, + PRINT_WIDTH = 1 << 10, + PRINT_HEIGHT = 1 << 11, + PRINT_LAST_LAYER = 1 << 12, + PRINT_KB_LAYOUT = 1 << 13, + PRINT_KEYMODE = 1 << 14, + PRINT_SCALEFACTOR = 1 << 15, + PRINT_FRAME = 1 << 16, + PRINT_ALL = (1 << 17) - 1 // 所有位都设为1 +}; typedef struct Pertag Pertag; typedef struct Monitor Monitor; @@ -187,13 +226,13 @@ typedef struct { char *v; char *v2; char *v3; - unsigned int ui; - unsigned int ui2; + uint32_t ui; + uint32_t ui2; } Arg; typedef struct { - unsigned int mod; - unsigned int button; + uint32_t mod; + uint32_t button; int (*func)(const Arg *); const Arg arg; } Button; // 鼠标按键 @@ -204,8 +243,8 @@ typedef struct { } KeyMode; typedef struct { - unsigned int mod; - unsigned int dir; + uint32_t mod; + uint32_t dir; int (*func)(const Arg *); const Arg arg; } Axis; @@ -233,28 +272,37 @@ struct dwl_animation { bool tagouting; bool begin_fade_in; bool tag_from_rule; - unsigned int total_frames; - unsigned int passed_frames; - unsigned int duration; + uint32_t time_started; + uint32_t duration; struct wlr_box initial; struct wlr_box current; int action; }; +struct dwl_opacity_animation { + bool running; + float current_opacity; + float target_opacity; + float initial_opacity; + uint32_t time_started; + uint32_t duration; + float current_border_color[4]; + float target_border_color[4]; + float initial_border_color[4]; +}; + typedef struct { float width_scale; float height_scale; int width; int height; - double percent; - float opacity; enum corner_location corner_location; bool should_scale; } BufferData; struct Client { /* Must keep these three elements in this order */ - unsigned int type; /* XDGShell or X11* */ + uint32_t type; /* XDGShell or X11* */ struct wlr_box geom, pending, float_geom, animainit_geom, overview_backup_geom, current, drag_begin_geom; /* layout-relative, includes border */ @@ -286,19 +334,19 @@ struct Client { struct wl_listener set_hints; struct wl_listener set_geometry; #endif - unsigned int bw; - unsigned int tags, oldtags, mini_restore_tag; + uint32_t bw; + uint32_t tags, oldtags, mini_restore_tag; bool dirty; - unsigned int configure_serial; + uint32_t configure_serial; struct wlr_foreign_toplevel_handle_v1 *foreign_toplevel; int isfloating, isurgent, isfullscreen, isfakefullscreen, - need_float_size_reduce, isminied, isoverlay, isnosizehint, + need_float_size_reduce, isminimized, isoverlay, isnosizehint, ignore_maximize, ignore_minimize; - int ismaxmizescreen; + int ismaximizescreen; int overview_backup_bw; int fullscreen_backup_x, fullscreen_backup_y, fullscreen_backup_w, fullscreen_backup_h; - int overview_isfullscreenbak, overview_ismaxmizescreenbak, + int overview_isfullscreenbak, overview_ismaximizescreenbak, overview_isfloatingbak; struct wlr_xdg_toplevel_decoration_v1 *decoration; @@ -306,6 +354,8 @@ struct Client { struct wl_listener foreign_fullscreen_request; struct wl_listener foreign_close_request; struct wl_listener foreign_destroy; + struct wl_listener foreign_minimize_request; + struct wl_listener foreign_maximize_request; struct wl_listener set_decoration_mode; struct wl_listener destroy_decoration; @@ -316,6 +366,9 @@ struct Client { int is_scratchpad_show; int isglobal; int isnoborder; + int isnoshadow; + int isnoradius; + int isnoanimation; int isopensilent; int istagsilent; int iskilling; @@ -326,6 +379,7 @@ struct Client { float scroller_proportion; bool need_output_flush; struct dwl_animation animation; + struct dwl_opacity_animation opacity_animation; int isterm, noswallow; int allow_csd; int force_maximize; @@ -335,6 +389,7 @@ struct Client { bool drag_to_tile; bool scratchpad_switching_mon; bool fake_no_border; + int nofocus; int nofadein; int nofadeout; int no_force_center; @@ -343,12 +398,17 @@ struct Client { float unfocused_opacity; char oldmonname[128]; int noblur; - double master_mfact_per, master_inner_per, stack_innder_per; - double old_master_mfact_per, old_master_inner_per, old_stack_innder_per; + double master_mfact_per, master_inner_per, stack_inner_per; + double old_master_mfact_per, old_master_inner_per, old_stack_inner_per; double old_scroller_pproportion; bool ismaster; bool cursor_in_upper_half, cursor_in_left_half; bool isleftstack; + int tearing_hint; + int force_tearing; + int allow_shortcuts_inhibit; + float scroller_proportion_single; + bool isfocusing; }; typedef struct { @@ -358,7 +418,7 @@ typedef struct { } DwlIpcOutput; typedef struct { - unsigned int mod; + uint32_t mod; xkb_keysym_t keysym; int (*func)(const Arg *); const Arg arg; @@ -369,8 +429,8 @@ typedef struct { int nsyms; const xkb_keysym_t *keysyms; /* invalid if nsyms == 0 */ - unsigned int mods; /* invalid if nsyms == 0 */ - unsigned int keycode; + uint32_t mods; /* invalid if nsyms == 0 */ + uint32_t keycode; struct wl_event_source *key_repeat_source; struct wl_listener modifiers; @@ -378,9 +438,15 @@ typedef struct { struct wl_listener destroy; } KeyboardGroup; +typedef struct { + struct wlr_keyboard_shortcuts_inhibitor_v1 *inhibitor; + struct wl_listener destroy; + struct wl_list link; +} KeyboardShortcutsInhibitor; + typedef struct { /* Must keep these three elements in this order */ - unsigned int type; /* LayerShell */ + uint32_t type; /* LayerShell */ struct wlr_box geom, current, pending, animainit_geom; Monitor *mon; struct wlr_scene_tree *scene; @@ -411,13 +477,14 @@ typedef struct { const char *symbol; void (*arrange)(Monitor *); const char *name; - unsigned int id; + uint32_t id; } Layout; struct Monitor { struct wl_list link; struct wlr_output *wlr_output; struct wlr_scene_output *scene_output; + struct wlr_output_state pending; struct wl_listener frame; struct wl_listener destroy; struct wl_listener request_state; @@ -427,8 +494,8 @@ struct Monitor { struct wlr_box w; /* window area, layout-relative */ struct wl_list layers[4]; /* LayerSurface::link */ const Layout *lt; - unsigned int seltags; - unsigned int tagset[2]; + uint32_t seltags; + uint32_t tagset[2]; double mfact; int nmaster; @@ -441,10 +508,10 @@ struct Monitor { Client *sel, *prevsel; int isoverview; int is_in_hotarea; - int gamma_lut_changed; int asleep; - unsigned int visible_clients; - unsigned int visible_tiling_clients; + uint32_t visible_clients; + uint32_t visible_tiling_clients; + uint32_t visible_scroll_tiling_clients; struct wlr_scene_optimized_blur *blur; char last_surface_ws_name[256]; struct wlr_ext_workspace_group_handle_v1 *ext_group; @@ -475,7 +542,7 @@ arrange(Monitor *m, static void arrangelayer(Monitor *m, struct wl_list *list, struct wlr_box *usable_area, int exclusive); static void arrangelayers(Monitor *m); -static char *get_autostart_path(char *, unsigned int); // 自启动命令执行 +static void handle_print_status(struct wl_listener *listener, void *data); static void axisnotify(struct wl_listener *listener, void *data); // 滚轮事件处理 static void buttonpress(struct wl_listener *listener, @@ -540,21 +607,20 @@ static void gpureset(struct wl_listener *listener, void *data); static int keyrepeat(void *data); static void inputdevice(struct wl_listener *listener, void *data); -static int keybinding(unsigned int mods, xkb_keysym_t sym, - unsigned int keycode); +static int keybinding(uint32_t state, bool locked, uint32_t mods, + xkb_keysym_t sym, uint32_t keycode); static void keypress(struct wl_listener *listener, void *data); static void keypressmod(struct wl_listener *listener, void *data); static bool keypressglobal(struct wlr_surface *last_surface, struct wlr_keyboard *keyboard, - struct wlr_keyboard_key_event *event, - unsigned int mods, xkb_keysym_t keysym, - unsigned int keycode); + struct wlr_keyboard_key_event *event, uint32_t mods, + xkb_keysym_t keysym, uint32_t keycode); static void locksession(struct wl_listener *listener, void *data); static void mapnotify(struct wl_listener *listener, void *data); static void maximizenotify(struct wl_listener *listener, void *data); static void minimizenotify(struct wl_listener *listener, void *data); static void motionabsolute(struct wl_listener *listener, void *data); -static void motionnotify(unsigned int time, struct wlr_input_device *device, +static void motionnotify(uint32_t time, struct wlr_input_device *device, double sx, double sy, double sx_unaccel, double sy_unaccel); static void motionrelative(struct wl_listener *listener, void *data); @@ -568,12 +634,13 @@ static void outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int test); static void outputmgrtest(struct wl_listener *listener, void *data); static void pointerfocus(Client *c, struct wlr_surface *surface, double sx, - double sy, unsigned int time); + double sy, uint32_t time); static void printstatus(void); static void quitsignal(int signo); static void powermgrsetmode(struct wl_listener *listener, void *data); static void rendermon(struct wl_listener *listener, void *data); static void requestdecorationmode(struct wl_listener *listener, void *data); +static void requestdrmlease(struct wl_listener *listener, void *data); static void requeststartdrag(struct wl_listener *listener, void *data); static void resize(Client *c, struct wlr_box geo, int interact); static void run(char *startup_cmd); @@ -581,11 +648,11 @@ static void setcursor(struct wl_listener *listener, void *data); static void setfloating(Client *c, int floating); static void setfakefullscreen(Client *c, int fakefullscreen); static void setfullscreen(Client *c, int fullscreen); -static void setmaxmizescreen(Client *c, int maxmizescreen); -static void reset_maxmizescreen_size(Client *c); +static void setmaximizescreen(Client *c, int maximizescreen); +static void reset_maximizescreen_size(Client *c); static void setgaps(int oh, int ov, int ih, int iv); -static void setmon(Client *c, Monitor *m, unsigned int newtags, bool focus); +static void setmon(Client *c, Monitor *m, uint32_t newtags, bool focus); static void setpsel(struct wl_listener *listener, void *data); static void setsel(struct wl_listener *listener, void *data); static void setup(void); @@ -600,7 +667,9 @@ static void urgent(struct wl_listener *listener, void *data); static void view(const Arg *arg, bool want_animation); static void handlesig(int signo); - +static void +handle_keyboard_shortcuts_inhibit_new_inhibitor(struct wl_listener *listener, + void *data); static void virtualkeyboard(struct wl_listener *listener, void *data); static void virtualpointer(struct wl_listener *listener, void *data); static void warp_cursor(const Client *c); @@ -614,7 +683,7 @@ static Client *termforwin(Client *w); static void swallow(Client *c, Client *w); static void warp_cursor_to_selmon(Monitor *m); -unsigned int want_restore_fullscreen(Client *target_client); +uint32_t want_restore_fullscreen(Client *target_client); static void overview_restore(Client *c, const Arg *arg); static void overview_backup(Client *c); static int applyrulesgeom(Client *c); @@ -627,7 +696,7 @@ static void tag_client(const Arg *arg, Client *target_client); static struct wlr_box setclient_coordinate_center(Client *c, struct wlr_box geom, int offsetx, int offsety); -static unsigned int get_tags_first_tag(unsigned int tags); +static uint32_t get_tags_first_tag(uint32_t tags); static struct wlr_output_mode * get_nearest_output_mode(struct wlr_output *output, int width, int height, @@ -658,11 +727,11 @@ static bool check_hit_no_border(Client *c); static void reset_keyboard_layout(void); static void client_update_oldmonname_record(Client *c, Monitor *m); static void pending_kill_client(Client *c); -static unsigned int get_tags_first_tag_num(unsigned int source_tags); +static uint32_t get_tags_first_tag_num(uint32_t source_tags); static void set_layer_open_animaiton(LayerSurface *l, struct wlr_box geo); static void init_fadeout_layers(LayerSurface *l); -static void layer_actual_size(LayerSurface *l, unsigned int *width, - unsigned int *height); +static void layer_actual_size(LayerSurface *l, uint32_t *width, + uint32_t *height); static void get_layer_target_geometry(LayerSurface *l, struct wlr_box *target_box); static void scene_buffer_apply_effect(struct wlr_scene_buffer *buffer, int sx, @@ -678,21 +747,24 @@ wlr_scene_tree_snapshot(struct wlr_scene_node *node, struct wlr_scene_tree *parent); static bool is_scroller_layout(Monitor *m); static void create_output(struct wlr_backend *backend, void *data); -static const char *get_layout_abbr(const char *full_name); +static void get_layout_abbr(char *abbr, const char *full_name); static void apply_named_scratchpad(Client *target_client); static Client *get_client_by_id_or_title(const char *arg_id, const char *arg_title); static bool switch_scratchpad_client_state(Client *c); static bool check_trackpad_disabled(struct wlr_pointer *pointer); -static unsigned int get_tag_status(unsigned int tag, Monitor *m); +static uint32_t get_tag_status(uint32_t tag, Monitor *m); static void enable_adaptive_sync(Monitor *m, struct wlr_output_state *state); static Client *get_next_stack_client(Client *c, bool reverse); static void set_float_malposition(Client *tc); static void set_size_per(Monitor *m, Client *c); static void resize_tile_client(Client *grabc, bool isdrag, int offsetx, - int offsety, unsigned int time); + int offsety, uint32_t time); static void refresh_monitors_workspaces_status(Monitor *m); static void init_client_properties(Client *c); +static float *get_border_color(Client *c); +static void request_fresh_all_monitors(void); +static void clear_fullscreen_and_maximized_state(Monitor *m); #include "data/static_keymap.h" #include "dispatch/bind_declare.h" @@ -702,11 +774,10 @@ static void init_client_properties(Client *c); static const char broken[] = "broken"; static pid_t child_pid = -1; static int locked; -static unsigned int locked_mods = 0; +static uint32_t locked_mods = 0; static void *exclusive_focus; static struct wl_display *dpy; static struct wl_event_loop *event_loop; -static struct wlr_relative_pointer_manager_v1 *pointer_manager; static struct wlr_backend *backend; static struct wlr_backend *headless_backend; static struct wlr_scene *scene; @@ -727,9 +798,13 @@ static struct wlr_idle_inhibit_manager_v1 *idle_inhibit_mgr; static struct wlr_layer_shell_v1 *layer_shell; static struct wlr_output_manager_v1 *output_mgr; static struct wlr_virtual_keyboard_manager_v1 *virtual_keyboard_mgr; +static struct wlr_keyboard_shortcuts_inhibit_manager_v1 + *keyboard_shortcuts_inhibit; static struct wlr_virtual_pointer_manager_v1 *virtual_pointer_mgr; static struct wlr_output_power_manager_v1 *power_mgr; static struct wlr_pointer_gestures_v1 *pointer_gestures; +static struct wlr_drm_lease_v1_manager *drm_lease_manager; +struct mango_print_status_manager *print_status_manager; static struct wlr_cursor *cursor; static struct wlr_xcursor_manager *cursor_mgr; @@ -749,7 +824,8 @@ static struct wlr_pointer_constraint_v1 *active_constraint; static struct wlr_seat *seat; static KeyboardGroup *kb_group; static struct wl_list inputdevices; -static unsigned int cursor_mode; +static struct wl_list keyboard_shortcut_inhibitors; +static uint32_t cursor_mode; static Client *grabc; static int grabcx, grabcy; /* client-relative */ static int drag_begin_cursorx, drag_begin_cursory; /* client-relative */ @@ -766,7 +842,7 @@ static int axis_apply_time = 0; static int axis_apply_dir = 0; static int scroller_focus_lock = 0; -static unsigned int swipe_fingers = 0; +static uint32_t swipe_fingers = 0; static double swipe_dx = 0; static double swipe_dy = 0; @@ -776,10 +852,14 @@ struct dvec2 *baked_points_move; struct dvec2 *baked_points_open; struct dvec2 *baked_points_tag; struct dvec2 *baked_points_close; +struct dvec2 *baked_points_focus; +struct dvec2 *baked_points_opafadein; +struct dvec2 *baked_points_opafadeout; static struct wl_event_source *hide_source; static bool cursor_hidden = false; static bool tag_combo = false; +static const char *cli_config_path = NULL; static KeyMode keymode = { .mode = {'d', 'e', 'f', 'a', 'u', 'l', 't', '\0'}, .isdefault = true, @@ -795,7 +875,7 @@ static struct { #include "config/preset.h" struct Pertag { - unsigned int curtag, prevtag; /* current and previous tag */ + uint32_t curtag, prevtag; /* current and previous tag */ int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */ float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */ bool no_hide[LENGTH(tags) + 1]; /* no_hide per tag */ @@ -803,6 +883,10 @@ struct Pertag { *ltidxs[LENGTH(tags) + 1]; /* matrix of tags and layouts indexes */ }; +static struct wl_signal mango_print_status; + +static struct wl_listener print_status_listener = {.notify = + handle_print_status}; static struct wl_listener cursor_axis = {.notify = axisnotify}; static struct wl_listener cursor_button = {.notify = buttonpress}; static struct wl_listener cursor_frame = {.notify = cursorframe}; @@ -833,6 +917,9 @@ static struct wl_listener request_set_cursor_shape = {.notify = setcursorshape}; static struct wl_listener request_start_drag = {.notify = requeststartdrag}; static struct wl_listener start_drag = {.notify = startdrag}; static struct wl_listener new_session_lock = {.notify = locksession}; +static struct wl_listener drm_lease_request = {.notify = requestdrmlease}; +static struct wl_listener keyboard_shortcuts_inhibit_new_inhibitor = { + .notify = handle_keyboard_shortcuts_inhibit_new_inhibitor}; #ifdef XWAYLAND static void activatex11(struct wl_listener *listener, void *data); @@ -883,22 +970,40 @@ void applybounds(Client *c, struct wlr_box *bbox) { c->geom.y = bbox->y; } +void clear_fullscreen_and_maximized_state(Monitor *m) { + Client *fc = NULL; + wl_list_for_each(fc, &clients, link) { + if (fc && VISIBLEON(fc, m) && ISFULLSCREEN(fc)) { + clear_fullscreen_flag(fc); + } + } +} + /*清除全屏标志,还原全屏时清0的border*/ void clear_fullscreen_flag(Client *c) { + + if ((c->mon->pertag->ltidxs[get_tags_first_tag_num(c->tags)]->id == + SCROLLER || + c->mon->pertag->ltidxs[get_tags_first_tag_num(c->tags)]->id == + VERTICAL_SCROLLER) && + !c->isfloating) { + return; + } + if (c->isfullscreen) { setfullscreen(c, false); } - if (c->ismaxmizescreen) { - setmaxmizescreen(c, 0); + if (c->ismaximizescreen) { + setmaximizescreen(c, 0); } } void show_scratchpad(Client *c) { c->is_scratchpad_show = 1; - if (c->isfullscreen || c->ismaxmizescreen) { + if (c->isfullscreen || c->ismaximizescreen) { c->isfullscreen = 0; // 清除窗口全屏标志 - c->ismaxmizescreen = 0; + c->ismaximizescreen = 0; c->bw = c->isnoborder ? 0 : borderpx; } @@ -938,8 +1043,8 @@ void swallow(Client *c, Client *w) { c->isfloating = w->isfloating; c->isurgent = w->isurgent; c->isfullscreen = w->isfullscreen; - c->ismaxmizescreen = w->ismaxmizescreen; - c->isminied = w->isminied; + c->ismaximizescreen = w->ismaximizescreen; + c->isminimized = w->isminimized; c->is_in_scratchpad = w->is_in_scratchpad; c->is_scratchpad_show = w->is_scratchpad_show; c->tags = w->tags; @@ -959,7 +1064,7 @@ void swallow(Client *c, Client *w) { if (!c->foreign_toplevel && c->mon) add_foreign_toplevel(c); - if (c->isminied && c->foreign_toplevel) { + if (c->isminimized && c->foreign_toplevel) { wlr_foreign_toplevel_handle_v1_set_activated(c->foreign_toplevel, false); wlr_foreign_toplevel_handle_v1_set_minimized(c->foreign_toplevel, true); @@ -1103,13 +1208,18 @@ static void apply_rule_properties(Client *c, const ConfigWinRule *r) { APPLY_INT_PROP(c, r, isterm); APPLY_INT_PROP(c, r, allow_csd); APPLY_INT_PROP(c, r, force_maximize); + APPLY_INT_PROP(c, r, force_tearing); APPLY_INT_PROP(c, r, noswallow); + APPLY_INT_PROP(c, r, nofocus); APPLY_INT_PROP(c, r, nofadein); APPLY_INT_PROP(c, r, nofadeout); APPLY_INT_PROP(c, r, no_force_center); APPLY_INT_PROP(c, r, isfloating); APPLY_INT_PROP(c, r, isfullscreen); APPLY_INT_PROP(c, r, isnoborder); + APPLY_INT_PROP(c, r, isnoshadow); + APPLY_INT_PROP(c, r, isnoradius); + APPLY_INT_PROP(c, r, isnoanimation); APPLY_INT_PROP(c, r, isopensilent); APPLY_INT_PROP(c, r, istagsilent); APPLY_INT_PROP(c, r, isnamedscratchpad); @@ -1120,8 +1230,10 @@ static void apply_rule_properties(Client *c, const ConfigWinRule *r) { APPLY_INT_PROP(c, r, isnosizehint); APPLY_INT_PROP(c, r, isunglobal); APPLY_INT_PROP(c, r, noblur); + APPLY_INT_PROP(c, r, allow_shortcuts_inhibit); APPLY_FLOAT_PROP(c, r, scroller_proportion); + APPLY_FLOAT_PROP(c, r, scroller_proportion_single); APPLY_FLOAT_PROP(c, r, focused_opacity); APPLY_FLOAT_PROP(c, r, unfocused_opacity); @@ -1213,13 +1325,18 @@ void set_float_malposition(Client *tc) { void applyrules(Client *c) { /* rule matching */ const char *appid, *title; - unsigned int i, newtags = 0; + uint32_t i, newtags = 0; const ConfigWinRule *r; - Monitor *mon = selmon, *m = NULL; + Monitor *m = NULL; Client *fc = NULL; bool hit_rule_pos = false; + Client *parent = NULL; - c->isfloating = client_is_float_type(c); + parent = client_get_parent(c); + + Monitor *mon = parent && parent->mon ? parent->mon : selmon; + + c->isfloating = client_is_float_type(c) || parent; if (!(appid = client_get_appid(c))) appid = broken; if (!(title = client_get_title(c))) @@ -1236,8 +1353,12 @@ void applyrules(Client *c) { // set general properties apply_rule_properties(c, r); - // set tags - newtags |= (r->tags > 0) ? r->tags : 0; + // // set tags + if (r->tags > 0) { + newtags |= r->tags; + } else if (parent) { + newtags = parent->tags; + } // set monitor of client wl_list_for_each(m, &mons, link) { @@ -1277,8 +1398,10 @@ void applyrules(Client *c) { // if no geom rule hit and is normal winodw, use the center pos and record // the hit size if (!hit_rule_pos && - (!client_is_x11(c) || !client_should_ignore_focus(c))) { + (!client_is_x11(c) || (c->geom.x == 0 && c->geom.y == 0))) { c->float_geom = c->geom = setclient_coordinate_center(c, c->geom, 0, 0); + } else { + c->float_geom = c->geom; } /*-----------------------apply rule action-------------------------*/ @@ -1292,7 +1415,7 @@ void applyrules(Client *c) { if (!c->noswallow && !c->isfloating && !client_is_float_type(c) && !c->surface.xdg->initial_commit) { Client *p = termforwin(c); - if (p) { + if (p && !p->isminimized) { c->swallowedby = p; p->swallowing = c; wl_list_remove(&c->link); @@ -1307,8 +1430,10 @@ void applyrules(Client *c) { int fullscreen_state_backup = c->isfullscreen || client_wants_fullscreen(c); setmon(c, mon, newtags, - !c->isopensilent && (!c->istagsilent || !newtags || - newtags & mon->tagset[mon->seltags])); + !c->isopensilent && + !(client_is_x11_popup(c) && client_should_ignore_focus(c)) && + (!c->istagsilent || !newtags || + newtags & mon->tagset[mon->seltags])); if (c->mon && !(c->mon == selmon && c->tags & c->mon->tagset[c->mon->seltags]) && @@ -1378,9 +1503,9 @@ void apply_window_snap(Client *c) { int snap_up_mon = 0, snap_down_mon = 0, snap_left_mon = 0, snap_right_mon = 0; - unsigned int cbw = !render_border || c->fake_no_border ? borderpx : 0; - unsigned int tcbw; - unsigned int cx, cy, cw, ch, tcx, tcy, tcw, tch; + uint32_t cbw = !render_border || c->fake_no_border ? borderpx : 0; + uint32_t tcbw; + uint32_t cx, cy, cw, ch, tcx, tcy, tcw, tch; cx = c->geom.x + cbw; cy = c->geom.y + cbw; cw = c->geom.width - 2 * cbw; @@ -1471,12 +1596,19 @@ void apply_window_snap(Client *c) { resize(c, c->geom, 0); } +void focuslayer(LayerSurface *l) { + focusclient(NULL, 0); + dwl_im_relay_set_focus(dwl_input_method_relay, l->layer_surface->surface); + client_notify_enter(l->layer_surface->surface, wlr_seat_get_keyboard(seat)); +} + void reset_exclusive_layer(Monitor *m) { LayerSurface *l = NULL; int i; - unsigned int layers_above_shell[] = { + uint32_t layers_above_shell[] = { ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY, ZWLR_LAYER_SHELL_V1_LAYER_TOP, + ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM, }; if (!m) @@ -1484,18 +1616,24 @@ void reset_exclusive_layer(Monitor *m) { for (i = 0; i < (int)LENGTH(layers_above_shell); i++) { wl_list_for_each_reverse(l, &m->layers[layers_above_shell[i]], link) { + if (l == exclusive_focus && + l->layer_surface->current.keyboard_interactive != + ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE) + exclusive_focus = NULL; + if (l->layer_surface->current.keyboard_interactive == + ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE && + l->layer_surface->surface == + seat->keyboard_state.focused_surface) + focusclient(focustop(selmon), 1); + if (locked || l->layer_surface->current.keyboard_interactive != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE || !l->mapped || l == exclusive_focus) continue; /* Deactivate the focused client. */ - focusclient(NULL, 0); exclusive_focus = l; - dwl_im_relay_set_focus(dwl_input_method_relay, - l->layer_surface->surface); - client_notify_enter(l->layer_surface->surface, - wlr_seat_get_keyboard(seat)); + focuslayer(l); return; } } @@ -1532,10 +1670,10 @@ axisnotify(struct wl_listener *listener, void *data) { * for example when you move the scroll wheel. */ struct wlr_pointer_axis_event *event = data; struct wlr_keyboard *keyboard, *hard_keyboard; - unsigned int mods, hard_mods; + uint32_t mods, hard_mods; AxisBinding *a; int ji; - unsigned int adir; + uint32_t adir; // IDLE_NOTIFY_ACTIVITY; handlecursoractivity(); wlr_idle_notifier_v1_notify_activity(idle_notifier, seat); @@ -1581,19 +1719,20 @@ axisnotify(struct wl_listener *listener, void *data) { * implemented checking the event's orientation and the delta of the event */ /* Notify the client with pointer focus of the axis event. */ - wlr_seat_pointer_notify_axis(seat, // 滚轮事件发送给客户端也就是窗口 - event->time_msec, event->orientation, - event->delta, event->delta_discrete, - event->source, event->relative_direction); + wlr_seat_pointer_notify_axis( + seat, // 滚轮事件发送给客户端也就是窗口 + event->time_msec, event->orientation, event->delta * axis_scroll_factor, + roundf(event->delta_discrete * axis_scroll_factor), event->source, + event->relative_direction); } int ongesture(struct wlr_pointer_swipe_end_event *event) { struct wlr_keyboard *keyboard, *hard_keyboard; - unsigned int mods, hard_mods; + uint32_t mods, hard_mods; const GestureBinding *g; - unsigned int motion; - unsigned int adx = (int)round(fabs(swipe_dx)); - unsigned int ady = (int)round(fabs(swipe_dy)); + uint32_t motion; + uint32_t adx = (int)round(fabs(swipe_dx)); + uint32_t ady = (int)round(fabs(swipe_dy)); int handled = 0; int ji; @@ -1758,7 +1897,7 @@ void // 鼠标按键事件 buttonpress(struct wl_listener *listener, void *data) { struct wlr_pointer_button_event *event = data; struct wlr_keyboard *hard_keyboard, *keyboard; - unsigned int hard_mods, mods; + uint32_t hard_mods, mods; Client *c = NULL; LayerSurface *l = NULL; struct wlr_surface *surface; @@ -1796,11 +1935,7 @@ buttonpress(struct wl_listener *listener, void *data) { if (l && !exclusive_focus && l->layer_surface->current.keyboard_interactive == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND) { - focusclient(NULL, 0); - dwl_im_relay_set_focus(dwl_input_method_relay, - l->layer_surface->surface); - client_notify_enter(l->layer_surface->surface, - wlr_seat_get_keyboard(seat)); + focuslayer(l); } } @@ -1874,16 +2009,27 @@ buttonpress(struct wl_listener *listener, void *data) { } void checkidleinhibitor(struct wlr_surface *exclude) { - int inhibited = 0, unused_lx, unused_ly; + int inhibited = 0; + Client *c = NULL; + struct wlr_surface *surface = NULL; struct wlr_idle_inhibitor_v1 *inhibitor; + wl_list_for_each(inhibitor, &idle_inhibit_mgr->inhibitors, link) { - struct wlr_surface *surface = - wlr_surface_get_root_surface(inhibitor->surface); + surface = wlr_surface_get_root_surface(inhibitor->surface); + + if (exclude == surface) { + continue; + } + + toplevel_from_wlr_surface(inhibitor->surface, &c, NULL); + + if (idleinhibit_ignore_visible) { + inhibited = 1; + break; + } + struct wlr_scene_tree *tree = surface->data; - if (exclude != surface && - (inhibit_regardless_of_visibility || - (!tree || - wlr_scene_node_coords(&tree->node, &unused_lx, &unused_ly)))) { + if (!tree || (tree->node.enabled && (!c || !c->animation.tagouting))) { inhibited = 1; break; } @@ -1909,6 +2055,7 @@ void setcursorshape(struct wl_listener *listener, void *data) { } void cleanuplisteners(void) { + wl_list_remove(&print_status_listener.link); wl_list_remove(&cursor_axis.link); wl_list_remove(&cursor_button.link); wl_list_remove(&cursor_frame.link); @@ -1937,6 +2084,11 @@ void cleanuplisteners(void) { wl_list_remove(&request_start_drag.link); wl_list_remove(&start_drag.link); wl_list_remove(&new_session_lock.link); + wl_list_remove(&tearing_new_object.link); + wl_list_remove(&keyboard_shortcuts_inhibit_new_inhibitor.link); + if (drm_lease_manager) { + wl_list_remove(&drm_lease_request.link); + } #ifdef XWAYLAND wl_list_remove(&new_xwayland_surface.link); wl_list_remove(&xwayland_ready.link); @@ -1974,7 +2126,7 @@ void cleanup(void) { void cleanupmon(struct wl_listener *listener, void *data) { Monitor *m = wl_container_of(listener, m, destroy); LayerSurface *l = NULL, *tmp = NULL; - unsigned int i; + uint32_t i; /* m->layers[i] are intentionally not unlinked */ for (i = 0; i < LENGTH(m->layers); i++) { @@ -2002,6 +2154,7 @@ void cleanupmon(struct wl_listener *listener, void *data) { wlr_scene_node_destroy(&m->blur->node); m->blur = NULL; } + m->wlr_output->data = NULL; free(m->pertag); free(m); } @@ -2118,6 +2271,13 @@ void maplayersurfacenotify(struct wl_listener *listener, void *data) { } // 刷新布局,让窗口能感应到exclude_zone变化以及设置独占表面 arrangelayers(l->mon); + + // 按需交互layer需要像正常窗口一样抢占非独占layer的焦点 + if (!exclusive_focus && + l->layer_surface->current.keyboard_interactive == + ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND) { + focuslayer(l); + } } void commitlayersurfacenotify(struct wl_listener *listener, void *data) { @@ -2380,14 +2540,14 @@ KeyboardGroup *createkeyboardgroup(void) { xkb_mod_index_t mod_index = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_NUM); if (mod_index != XKB_MOD_INVALID) - locked_mods |= (unsigned int)1 << mod_index; + locked_mods |= (uint32_t)1 << mod_index; } if (capslock) { xkb_mod_index_t mod_index = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_CAPS); if (mod_index != XKB_MOD_INVALID) - locked_mods |= (unsigned int)1 << mod_index; + locked_mods |= (uint32_t)1 << mod_index; } if (locked_mods) @@ -2511,7 +2671,7 @@ void createmon(struct wl_listener *listener, void *data) { * monitor) becomes available. */ struct wlr_output *wlr_output = data; const ConfigMonitorRule *r; - unsigned int i; + uint32_t i; int ji, jk; struct wlr_output_state state; Monitor *m = NULL; @@ -2521,8 +2681,17 @@ void createmon(struct wl_listener *listener, void *data) { if (!wlr_output_init_render(wlr_output, alloc, drw)) return; + if (wlr_output->non_desktop) { + if (drm_lease_manager) { + wlr_drm_lease_v1_manager_offer_output(drm_lease_manager, + wlr_output); + } + return; + } + m = wlr_output->data = ecalloc(1, sizeof(*m)); m->wlr_output = wlr_output; + m->wlr_output->data = m; wl_list_init(&m->dwl_ipc_outputs); @@ -2619,18 +2788,7 @@ void createmon(struct wl_listener *listener, void *data) { } // apply tag rule - for (i = 1; i <= config.tag_rules_count; i++) { - for (jk = 0; jk < LENGTH(layouts); jk++) { - if (config.tag_rules_count > 0 && - config.tag_rules[i - 1].layout_name && - strcmp(layouts[jk].name, config.tag_rules[i - 1].layout_name) == - 0) { - m->pertag->ltidxs[config.tag_rules[i - 1].id] = &layouts[jk]; - m->pertag->no_hide[config.tag_rules[i - 1].id] = - config.tag_rules[i - 1].no_hide; - } - } - } + parse_tagrule(m); /* The xdg-protocol specifies: * @@ -2930,7 +3088,9 @@ void destroylock(SessionLock *lock, int unlock) { if ((locked = !unlock)) goto destroy; - wlr_scene_node_set_enabled(&locked_bg->node, false); + if (locked_bg->node.enabled) { + wlr_scene_node_set_enabled(&locked_bg->node, false); + } focusclient(focustop(selmon), 0); motionnotify(0, NULL, 0, 0, 0, 0); @@ -3028,6 +3188,10 @@ void destroykeyboardgroup(struct wl_listener *listener, void *data) { } void focusclient(Client *c, int lift) { + + Client *last_focus_client = NULL; + Monitor *um = NULL; + struct wlr_surface *old_keyboard_focus_surface = seat->keyboard_state.focused_surface; @@ -3040,9 +3204,11 @@ void focusclient(Client *c, int lift) { if (c && !client_surface(c)->mapped) return; - if (c && client_should_ignore_focus(c)) { + if (c && client_should_ignore_focus(c) && client_is_x11_popup(c)) + return; + + if (c && c->nofocus) return; - } /* Raise client in stacking order if requested */ if (c && lift) @@ -3060,16 +3226,25 @@ void focusclient(Client *c, int lift) { if (c && !c->iskilling && !client_is_unmanaged(c) && c->mon) { + last_focus_client = selmon->sel; selmon = c->mon; selmon->prevsel = selmon->sel; selmon->sel = c; + c->isfocusing = true; + + if (last_focus_client && !last_focus_client->iskilling && + last_focus_client != c) { + last_focus_client->isfocusing = false; + client_set_unfocused_opacity_animation(last_focus_client); + } + + client_set_focused_opacity_animation(c); // decide whether need to re-arrange if (c && selmon->prevsel && (selmon->prevsel->tags & selmon->tagset[selmon->seltags]) && (c->tags & selmon->tagset[selmon->seltags]) && !c->isfloating && - !c->isfullscreen && !c->ismaxmizescreen && is_scroller_layout(selmon)) { arrange(selmon, false); } @@ -3080,7 +3255,15 @@ void focusclient(Client *c, int lift) { // change border color c->isurgent = 0; - setborder_color(c); + } + + // update other monitor focus disappear + wl_list_for_each(um, &mons, link) { + if (um->wlr_output->enabled && um != selmon && um->sel && + !um->sel->iskilling && um->sel->isfocusing) { + um->sel->isfocusing = false; + client_set_unfocused_opacity_animation(um->sel); + } } if (c && !c->iskilling && c->foreign_toplevel) @@ -3108,18 +3291,17 @@ void focusclient(Client *c, int lift) { * probably other clients */ } else if (w && !client_is_unmanaged(w) && (!c || !client_wants_focus(c))) { - setborder_color(w); - client_activate_surface(old_keyboard_focus_surface, 0); } } printstatus(); if (!c) { - /* With no client, all we have left is to clear focus */ - if (selmon && selmon->sel) - selmon->sel = - NULL; // 这个很关键,因为很多地方用到当前窗口做计算,不重置成NULL就会到处有野指针 + + if (selmon && selmon->sel && + (!VISIBLEON(selmon->sel, selmon) || selmon->sel->iskilling || + !client_surface(selmon->sel)->mapped)) + selmon->sel = NULL; // clear text input focus state dwl_im_relay_set_focus(dwl_input_method_relay, NULL); @@ -3162,7 +3344,7 @@ void inputdevice(struct wl_listener *listener, void *data) { /* This event is raised by the backend when a new input device becomes * available. */ struct wlr_input_device *device = data; - unsigned int caps; + uint32_t caps; switch (device->type) { case WLR_INPUT_DEVICE_KEYBOARD: @@ -3207,13 +3389,26 @@ int keyrepeat(void *data) { 1000 / group->wlr_group->keyboard.repeat_info.rate); for (i = 0; i < group->nsyms; i++) - keybinding(group->mods, group->keysyms[i], group->keycode); + keybinding(WL_KEYBOARD_KEY_STATE_PRESSED, false, group->mods, + group->keysyms[i], group->keycode); return 0; } +bool is_keyboard_shortcut_inhibitor(struct wlr_surface *surface) { + KeyboardShortcutsInhibitor *kbsinhibitor; + + wl_list_for_each(kbsinhibitor, &keyboard_shortcut_inhibitors, link) { + if (kbsinhibitor->inhibitor->surface == surface) { + return true; + } + } + return false; +} + int // 17 -keybinding(unsigned int mods, xkb_keysym_t sym, unsigned int keycode) { +keybinding(uint32_t state, bool locked, uint32_t mods, xkb_keysym_t sym, + uint32_t keycode) { /* * Here we handle compositor keybindings. This is when the compositor is * processing keys, rather than passing them on to the client for its @@ -3224,22 +3419,53 @@ keybinding(unsigned int mods, xkb_keysym_t sym, unsigned int keycode) { int ji; int isbreak = 0; + // not allow modifier keys to be used as a keybinding + if (keycode == 50 || keycode == 37 || keycode == 133 || keycode == 64 || + keycode == 62 || keycode == 108 || keycode == 105 || keycode == 134) + return false; + + if (is_keyboard_shortcut_inhibitor(seat->keyboard_state.focused_surface)) { + return false; + } + for (ji = 0; ji < config.key_bindings_count; ji++) { if (config.key_bindings_count < 1) break; + + if (locked && config.key_bindings[ji].islockapply == false) + continue; + + if (state == WL_KEYBOARD_KEY_STATE_RELEASED && + config.key_bindings[ji].isreleaseapply == false) + continue; + + if (state == WL_KEYBOARD_KEY_STATE_PRESSED && + config.key_bindings[ji].isreleaseapply == true) + continue; + + if (state != WL_KEYBOARD_KEY_STATE_PRESSED && + state != WL_KEYBOARD_KEY_STATE_RELEASED) + continue; + k = &config.key_bindings[ji]; if ((k->iscommonmode || (k->isdefaultmode && keymode.isdefault) || (strcmp(keymode.mode, k->mode) == 0)) && CLEANMASK(mods) == CLEANMASK(k->mod) && ((k->keysymcode.type == KEY_TYPE_SYM && - normalize_keysym(sym) == - normalize_keysym(k->keysymcode.keysym)) || + xkb_keysym_to_lower(sym) == + xkb_keysym_to_lower(k->keysymcode.keysym)) || (k->keysymcode.type == KEY_TYPE_CODE && - keycode == k->keysymcode.keycode)) && + (keycode == k->keysymcode.keycode.keycode1 || + keycode == k->keysymcode.keycode.keycode2 || + keycode == k->keysymcode.keycode.keycode3))) && k->func) { + if (!k->ispassapply) + handled = 1; + else + handled = 0; + isbreak = k->func(&k->arg); - handled = 1; if (isbreak) break; @@ -3250,10 +3476,10 @@ keybinding(unsigned int mods, xkb_keysym_t sym, unsigned int keycode) { bool keypressglobal(struct wlr_surface *last_surface, struct wlr_keyboard *keyboard, - struct wlr_keyboard_key_event *event, unsigned int mods, - xkb_keysym_t keysym, unsigned int keycode) { + struct wlr_keyboard_key_event *event, uint32_t mods, + xkb_keysym_t keysym, uint32_t keycode) { Client *c = NULL, *lastc = focustop(selmon); - unsigned int keycodes[32] = {0}; + uint32_t keycodes[32] = {0}; int reset = false; const char *appid = NULL; const char *title = NULL; @@ -3267,14 +3493,18 @@ bool keypressglobal(struct wlr_surface *last_surface, if (!r->globalkeybinding.mod || (!r->globalkeybinding.keysymcode.keysym && - !r->globalkeybinding.keysymcode.keycode)) + !r->globalkeybinding.keysymcode.keycode.keycode1 && + !r->globalkeybinding.keysymcode.keycode.keycode2 && + !r->globalkeybinding.keysymcode.keycode.keycode3)) continue; /* match key only (case insensitive) ignoring mods */ if (((r->globalkeybinding.keysymcode.type == KEY_TYPE_SYM && r->globalkeybinding.keysymcode.keysym == keysym) || (r->globalkeybinding.keysymcode.type == KEY_TYPE_CODE && - r->globalkeybinding.keysymcode.keycode == keycode)) && + (r->globalkeybinding.keysymcode.keycode.keycode1 == keycode || + r->globalkeybinding.keysymcode.keycode.keycode2 == keycode || + r->globalkeybinding.keysymcode.keycode.keycode3 == keycode))) && r->globalkeybinding.mod == mods) { wl_list_for_each(c, &clients, link) { if (c && c != lastc) { @@ -3325,34 +3555,35 @@ void keypress(struct wl_listener *listener, void *data) { #endif /* Translate libinput keycode -> xkbcommon */ - unsigned int keycode = event->keycode + 8; + uint32_t keycode = event->keycode + 8; /* Get a list of keysyms based on the keymap for this keyboard */ const xkb_keysym_t *syms; int nsyms = xkb_state_key_get_syms(group->wlr_group->keyboard.xkb_state, keycode, &syms); int handled = 0; - unsigned int mods = wlr_keyboard_get_modifiers(&group->wlr_group->keyboard); + uint32_t mods = wlr_keyboard_get_modifiers(&group->wlr_group->keyboard); wlr_idle_notifier_v1_notify_activity(idle_notifier, seat); // ov tab mode detect moe key release - if (ov_tab_mode && !locked && + if (ov_tab_mode && !locked && group == kb_group && event->state == WL_KEYBOARD_KEY_STATE_RELEASED && (keycode == 133 || keycode == 37 || keycode == 64 || keycode == 50 || keycode == 134 || keycode == 105 || keycode == 108 || keycode == 62) && selmon && selmon->sel) { if (selmon->isoverview && selmon->sel) { - toggleoverview(&(Arg){.i = -1}); + toggleoverview(&(Arg){.i = 1}); } } /* On _press_ if there is no active screen locker, * attempt to process a compositor keybinding. */ - if (!locked && event->state == WL_KEYBOARD_KEY_STATE_PRESSED) { - for (i = 0; i < nsyms; i++) - handled = keybinding(mods, syms[i], keycode) || handled; - } else if (event->state == WL_KEYBOARD_KEY_STATE_RELEASED) { + for (i = 0; i < nsyms; i++) + handled = + keybinding(event->state, locked, mods, syms[i], keycode) || handled; + + if (event->state == WL_KEYBOARD_KEY_STATE_RELEASED) { tag_combo = false; } @@ -3419,7 +3650,9 @@ void pending_kill_client(Client *c) { void locksession(struct wl_listener *listener, void *data) { struct wlr_session_lock_v1 *session_lock = data; SessionLock *lock; - wlr_scene_node_set_enabled(&locked_bg->node, true); + if (!allow_lock_transparent) { + wlr_scene_node_set_enabled(&locked_bg->node, true); + } if (cur_lock) { wlr_session_lock_v1_destroy(session_lock); return; @@ -3468,13 +3701,14 @@ static void iter_xdg_scene_buffers(struct wlr_scene_buffer *buffer, int sx, } void init_client_properties(Client *c) { - c->ismaxmizescreen = 0; + c->isfocusing = false; + c->ismaximizescreen = 0; c->isfullscreen = 0; c->need_float_size_reduce = 0; c->iskilling = 0; c->istagswitching = 0; c->isglobal = 0; - c->isminied = 0; + c->isminimized = 0; c->isoverlay = 0; c->isunglobal = 0; c->is_in_scratchpad = 0; @@ -3492,26 +3726,35 @@ void init_client_properties(Client *c) { c->fake_no_border = false; c->focused_opacity = focused_opacity; c->unfocused_opacity = unfocused_opacity; + c->nofocus = 0; c->nofadein = 0; c->nofadeout = 0; c->no_force_center = 0; c->isnoborder = 0; c->isnosizehint = 0; - c->ignore_maximize = 0; + c->isnoradius = 0; + c->isnoshadow = 0; + c->ignore_maximize = 1; c->ignore_minimize = 1; c->iscustomsize = 0; c->master_mfact_per = 0.0f; c->master_inner_per = 0.0f; - c->stack_innder_per = 0.0f; + c->stack_inner_per = 0.0f; c->isterm = 0; c->allow_csd = 0; - c->force_maximize = 1; + c->force_maximize = 0; + c->force_tearing = 0; + c->allow_shortcuts_inhibit = SHORTCUTS_INHIBIT_ENABLE; + c->scroller_proportion_single = 0.0f; + c->float_geom.width = 0; + c->float_geom.height = 0; + c->float_geom.x = 0; + c->float_geom.y = 0; } void // old fix to 0.5 mapnotify(struct wl_listener *listener, void *data) { /* Called when the surface is mapped, or ready to display on-screen. */ - Client *p = NULL; Client *at_client = NULL; Client *c = wl_container_of(listener, c, map); /* Create scene tree for this client and its border */ @@ -3529,7 +3772,7 @@ mapnotify(struct wl_listener *listener, void *data) { init_client_properties(c); // set special window properties - if (client_is_unmanaged(c) || client_should_ignore_focus(c)) { + if (client_is_unmanaged(c) || client_is_x11_popup(c)) { c->bw = 0; c->isnoborder = 1; } else { @@ -3582,9 +3825,9 @@ mapnotify(struct wl_listener *listener, void *data) { // tile at the top wl_list_insert(&clients, &c->link); // 新窗口是master,头部入栈 else if (selmon && is_scroller_layout(selmon) && - selmon->visible_tiling_clients > 0) { + selmon->visible_scroll_tiling_clients > 0) { - if (selmon->sel && ISTILED(selmon->sel) && + if (selmon->sel && ISSCROLLTILED(selmon->sel) && VISIBLEON(selmon->sel, selmon)) { at_client = selmon->sel; } else { @@ -3603,16 +3846,7 @@ mapnotify(struct wl_listener *listener, void *data) { wl_list_insert(clients.prev, &c->link); // 尾部入栈 wl_list_insert(&fstack, &c->flink); - /* Set initial monitor, tags, floating status, and focus: - * we always consider floating, clients that have parent and thus - * we set the same tags and monitor than its parent, if not - * try to apply rules for them */ - if ((p = client_get_parent(c))) { - c->isfloating = 1; - setmon(c, p->mon, p->tags, true); - } else { - applyrules(c); - } + applyrules(c); client_set_tiled(c, WLR_EDGE_TOP | WLR_EDGE_BOTTOM | WLR_EDGE_LEFT | WLR_EDGE_RIGHT); @@ -3630,36 +3864,27 @@ mapnotify(struct wl_listener *listener, void *data) { printstatus(); } -void // 0.5 custom -maximizenotify(struct wl_listener *listener, void *data) { - /* This event is raised when a client would like to maximize itself, - * typically because the user clicked on the maximize button on - * client-side decorations. dwl doesn't support maximization, but - * to conform to xdg-shell protocol we still must send a configure. - * Since xdg-shell protocol v5 we should ignore request of unsupported - * capabilities, just schedule a empty configure when the client uses <5 - * protocol version - * wlr_xdg_surface_schedule_configure() is used to send an empty reply. - */ - // Client *c = wl_container_of(listener, c, maximize); - // if (wl_resource_get_version(c->surface.xdg->toplevel->resource) - // < XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION) - // wlr_xdg_surface_schedule_configure(c->surface.xdg); - // togglemaxmizescreen(&(Arg){0}); +void maximizenotify(struct wl_listener *listener, void *data) { + Client *c = wl_container_of(listener, c, maximize); if (!c || !c->mon || c->iskilling || c->ignore_maximize) return; - if (c->ismaxmizescreen || c->isfullscreen) - setmaxmizescreen(c, 0); - else - setmaxmizescreen(c, 1); + if (!client_is_x11(c) && !c->surface.xdg->initialized) { + return; + } + + if (client_request_maximize(c, data)) { + setmaximizescreen(c, 1); + } else { + setmaximizescreen(c, 0); + } } void unminimize(Client *c) { if (c && c->is_in_scratchpad && c->is_scratchpad_show) { - c->isminied = 0; + c->isminimized = 0; c->is_scratchpad_show = 0; c->is_in_scratchpad = 0; c->isnamedscratchpad = 0; @@ -3667,7 +3892,7 @@ void unminimize(Client *c) { return; } - if (c && c->isminied) { + if (c && c->isminimized) { show_hide_client(c); c->is_scratchpad_show = 0; c->is_in_scratchpad = 0; @@ -3687,7 +3912,7 @@ void set_minimized(Client *c) { c->oldtags = c->mon->tagset[c->mon->seltags]; c->mini_restore_tag = c->tags; c->tags = 0; - c->isminied = 1; + c->isminimized = 1; c->is_in_scratchpad = 1; c->is_scratchpad_show = 0; focusclient(focustop(selmon), 1); @@ -3698,34 +3923,19 @@ void set_minimized(Client *c) { wl_list_insert(clients.prev, &c->link); // 插入尾部 } -void // 0.5 custom -minimizenotify(struct wl_listener *listener, void *data) { - /* This event is raised when a client would like to maximize itself, - * typically because the user clicked on the maximize button on - * client-side decorations. dwl doesn't support maximization, but - * to conform to xdg-shell protocol we still must send a configure. - * Since xdg-shell protocol v5 we should ignore request of unsupported - * capabilities, just schedule a empty configure when the client uses <5 - * protocol version - * wlr_xdg_surface_schedule_configure() is used to send an empty reply. - */ - // Client *c = wl_container_of(listener, c, maximize); - // if (wl_resource_get_version(c->surface.xdg->toplevel->resource) - // < XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION) - // wlr_xdg_surface_schedule_configure(c->surface.xdg); - // togglemaxmizescreen(&(Arg){0}); +void minimizenotify(struct wl_listener *listener, void *data) { Client *c = wl_container_of(listener, c, minimize); - if (!c || !c->mon || c->iskilling || c->isminied) + if (!c || !c->mon || c->iskilling || c->isminimized) return; if (client_request_minimize(c, data) && !c->ignore_minimize) { - if (!c->isminied) + if (!c->isminimized) set_minimized(c); client_set_minimized(c, true); } else { - if (c->isminied) + if (c->isminimized) unminimize(c); client_set_minimized(c, false); } @@ -3756,7 +3966,7 @@ void motionabsolute(struct wl_listener *listener, void *data) { motionnotify(event->time_msec, &event->pointer->base, dx, dy, dx, dy); } -void motionnotify(unsigned int time, struct wlr_input_device *device, double dx, +void motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double dy, double dx_unaccel, double dy_unaccel) { double sx = 0, sy = 0, sx_confined, sy_confined; Client *c = NULL, *w = NULL; @@ -3838,7 +4048,11 @@ void motionnotify(unsigned int time, struct wlr_input_device *device, double dx, .y = grabc->geom.y, .width = (int)round(cursor->x) - grabc->geom.x, .height = (int)round(cursor->y) - grabc->geom.y}; - resize(grabc, grabc->float_geom, 1); + if (last_apply_drap_time == 0 || + time - last_apply_drap_time > drag_refresh_interval) { + resize(grabc, grabc->float_geom, 1); + last_apply_drap_time = time; + } return; } else { resize_tile_client(grabc, true, 0, 0, time); @@ -3851,35 +4065,18 @@ void motionnotify(unsigned int time, struct wlr_input_device *device, double dx, if (!surface && !seat->drag && !cursor_hidden) wlr_cursor_set_xcursor(cursor, cursor_mgr, "default"); - if (c && c->mon && !c->animation.running && - (!(c->geom.x + c->geom.width > c->mon->m.x + c->mon->m.width || - c->geom.x < c->mon->m.x || - c->geom.y + c->geom.height > c->mon->m.y + c->mon->m.height || - c->geom.y < c->mon->m.y) || - !ISTILED(c))) { + if (c && c->mon && !c->animation.running && (INSIDEMON(c) || !ISTILED(c))) { scroller_focus_lock = 0; } should_lock = false; - if (!scroller_focus_lock || - !(c && c->mon && - (c->geom.x + c->geom.width > c->mon->m.x + c->mon->m.width || - c->geom.x < c->mon->m.x || - c->geom.y + c->geom.height > c->mon->m.y + c->mon->m.height || - c->geom.y < c->mon->m.y))) { - if (c && c->mon && is_scroller_layout(c->mon) && - (c->geom.x + c->geom.width > c->mon->m.x + c->mon->m.width || - c->geom.x < c->mon->m.x || - c->geom.y + c->geom.height > c->mon->m.y + c->mon->m.height || - c->geom.y < c->mon->m.y)) { + if (!scroller_focus_lock || !(c && c->mon && !INSIDEMON(c))) { + if (c && c->mon && is_scroller_layout(c->mon) && !INSIDEMON(c)) { should_lock = true; } if (!(!edge_scroller_pointer_focus && c && c->mon && - is_scroller_layout(c->mon) && - (c->geom.x < c->mon->m.x || c->geom.y < c->mon->m.y || - c->geom.x + c->geom.width > c->mon->m.x + c->mon->m.width || - c->geom.y + c->geom.height > c->mon->m.y + c->mon->m.height))) + is_scroller_layout(c->mon) && !INSIDEMON(c))) pointerfocus(c, surface, sx, sy, time); if (should_lock && c && c->mon && ISTILED(c) && c == c->mon->sel) { @@ -3981,7 +4178,7 @@ void outputmgrtest(struct wl_listener *listener, void *data) { } void pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy, - unsigned int time) { + uint32_t time) { struct timespec now; if (surface != seat->pointer_state.focused_surface && sloppyfocus && time && @@ -4006,20 +4203,8 @@ void pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy, wlr_seat_pointer_notify_motion(seat, time, sx, sy); } -void // 17 -printstatus(void) { - Monitor *m = NULL; - wl_list_for_each(m, &mons, link) { - if (!m->wlr_output->enabled) { - continue; - } - // Update workspace active states - dwl_ext_workspace_printstatus(m); - - // Update IPC output status - dwl_ipc_output_printstatus(m); - } -} +// 修改printstatus函数,接受掩码参数 +void printstatus(void) { wl_signal_emit(&mango_print_status, NULL); } void powermgrsetmode(struct wl_listener *listener, void *data) { struct wlr_output_power_v1_set_mode_event *event = data; @@ -4029,7 +4214,6 @@ void powermgrsetmode(struct wl_listener *listener, void *data) { if (!m) return; - m->gamma_lut_changed = 1; /* Reapply gamma LUT when re-enabling the ouput */ wlr_output_state_set_enabled(&state, event->mode); wlr_output_commit_state(m->wlr_output, &state); @@ -4059,10 +4243,11 @@ void rendermon(struct wl_listener *listener, void *data) { struct timespec now; bool need_more_frames = false; + bool frame_allow_tearing = check_tearing_frame_allow(m); + // 绘制层和淡出效果 for (i = 0; i < LENGTH(m->layers); i++) { layer_list = &m->layers[i]; - // Draw frames for all layer wl_list_for_each_safe(l, tmpl, layer_list, link) { need_more_frames = layer_draw_frame(l) || need_more_frames; } @@ -4076,27 +4261,36 @@ void rendermon(struct wl_listener *listener, void *data) { need_more_frames = layer_draw_fadeout_frame(l) || need_more_frames; } - // Draw frames for all clients + // 绘制客户端 wl_list_for_each(c, &clients, link) { need_more_frames = client_draw_frame(c) || need_more_frames; - if (!animations && c->configure_serial && !c->isfloating && - client_is_rendered_on_mon(c, m) && !client_is_stopped(c)) + if (!animations && !(allow_tearing && frame_allow_tearing) && + c->configure_serial && !c->isfloating && + client_is_rendered_on_mon(c, m) && !client_is_stopped(c)) { goto skip; + } } - wlr_scene_output_commit(m->scene_output, NULL); + // 只有在需要帧时才构建和提交状态 + if (allow_tearing && frame_allow_tearing) { + apply_tear_state(m); + } else { + wlr_scene_output_commit(m->scene_output, NULL); + } skip: - - // Send frame done notification + // 发送帧完成通知 clock_gettime(CLOCK_MONOTONIC, &now); - wlr_scene_output_send_frame_done(m->scene_output, &now); - - // // Clean up pending state - wlr_output_state_finish(&pending); + if (allow_tearing && frame_allow_tearing) { + wlr_scene_output_send_frame_done(m->scene_output, &now); + } else { + wlr_scene_output_send_frame_done(m->scene_output, &now); + wlr_output_state_finish(&pending); + } + // 如果需要更多帧,确保安排下一帧 if (need_more_frames) { - wlr_output_schedule_frame(m->wlr_output); + request_fresh_all_monitors(); } } @@ -4118,6 +4312,16 @@ void requestdecorationmode(struct wl_listener *listener, void *data) { } } +static void requestdrmlease(struct wl_listener *listener, void *data) { + struct wlr_drm_lease_request_v1 *req = data; + struct wlr_drm_lease_v1 *lease = wlr_drm_lease_request_v1_grant(req); + + if (!lease) { + wlr_log(WLR_ERROR, "Failed to grant lease request"); + wlr_drm_lease_request_v1_reject(req); + } +} + void requeststartdrag(struct wl_listener *listener, void *data) { struct wlr_seat_request_start_drag_event *event = data; @@ -4131,32 +4335,20 @@ void requeststartdrag(struct wl_listener *listener, void *data) { void setborder_color(Client *c) { if (!c || !c->mon) return; - if (c->isurgent) { - client_set_border_color(c, urgentcolor); - return; - } - if (c->is_in_scratchpad && selmon && c == selmon->sel) { - client_set_border_color(c, scratchpadcolor); - } else if (c->isglobal && selmon && c == selmon->sel) { - client_set_border_color(c, globalcolor); - } else if (c->isoverlay && selmon && c == selmon->sel) { - client_set_border_color(c, overlaycolor); - } else if (c->ismaxmizescreen && selmon && c == selmon->sel) { - client_set_border_color(c, maxmizescreencolor); - } else if (selmon && c == selmon->sel) { - client_set_border_color(c, focuscolor); - } else { - client_set_border_color(c, bordercolor); - } + + float *border_color = get_border_color(c); + memcpy(c->opacity_animation.target_border_color, border_color, + sizeof(c->opacity_animation.target_border_color)); + client_set_border_color(c, border_color); } void exchange_two_client(Client *c1, Client *c2) { Monitor *tmp_mon = NULL; - unsigned int tmp_tags; + uint32_t tmp_tags; double master_inner_per = 0.0f; double master_mfact_per = 0.0f; - double stack_innder_per = 0.0f; + double stack_inner_per = 0.0f; if (c1 == NULL || c2 == NULL || (!exchange_cross_monitor && c1->mon != c2->mon)) { @@ -4165,15 +4357,15 @@ void exchange_two_client(Client *c1, Client *c2) { master_inner_per = c1->master_inner_per; master_mfact_per = c1->master_mfact_per; - stack_innder_per = c1->stack_innder_per; + stack_inner_per = c1->stack_inner_per; c1->master_inner_per = c2->master_inner_per; c1->master_mfact_per = c2->master_mfact_per; - c1->stack_innder_per = c2->stack_innder_per; + c1->stack_inner_per = c2->stack_inner_per; c2->master_inner_per = master_inner_per; c2->master_mfact_per = master_mfact_per; - c2->stack_innder_per = stack_innder_per; + c2->stack_inner_per = stack_inner_per; struct wl_list *tmp1_prev = c1->link.prev; struct wl_list *tmp2_prev = c2->link.prev; @@ -4231,7 +4423,6 @@ run(char *startup_cmd) { set_env(); - char autostart_temp_path[1024]; /* Add a Unix socket to the Wayland display. */ const char *socket = wl_display_add_socket_auto(dpy); if (!socket) @@ -4245,9 +4436,7 @@ run(char *startup_cmd) { /* Now that the socket exists and the backend is started, run the * startup command */ - if (!startup_cmd) - startup_cmd = get_autostart_path(autostart_temp_path, - sizeof(autostart_temp_path)); + if (startup_cmd) { int piperw[2]; if (pipe(piperw) < 0) @@ -4340,14 +4529,14 @@ setfloating(Client *c, int floating) { if (floating == 1 && c != grabc) { - if (c->isfullscreen || c->ismaxmizescreen) { + if (c->isfullscreen || c->ismaximizescreen) { c->isfullscreen = 0; // 清除窗口全屏标志 - c->ismaxmizescreen = 0; + c->ismaximizescreen = 0; c->bw = c->isnoborder ? 0 : borderpx; } // 重新计算居中的坐标 - if (!client_is_x11(c) || !client_should_ignore_focus(c)) + if (!client_is_x11(c) || (c->geom.x == 0 && c->geom.y == 0)) target_box = setclient_coordinate_center(c, target_box, 0, 0); backup_box = c->geom; hit = applyrulesgeom(c); @@ -4410,7 +4599,7 @@ setfloating(Client *c, int floating) { printstatus(); } -void reset_maxmizescreen_size(Client *c) { +void reset_maximizescreen_size(Client *c) { c->geom.x = c->mon->w.x + gappoh; c->geom.y = c->mon->w.y + gappov; c->geom.width = c->mon->w.width - 2 * gappoh; @@ -4418,49 +4607,48 @@ void reset_maxmizescreen_size(Client *c) { resize(c, c->geom, 0); } -void setmaxmizescreen(Client *c, int maxmizescreen) { - struct wlr_box maxmizescreen_box; +void setmaximizescreen(Client *c, int maximizescreen) { + struct wlr_box maximizescreen_box; if (!c || !c->mon || !client_surface(c)->mapped || c->iskilling) return; - c->ismaxmizescreen = maxmizescreen; + if (c->mon->isoverview) + return; - if (maxmizescreen) { + c->ismaximizescreen = maximizescreen; + + if (maximizescreen) { if (c->isfullscreen) setfullscreen(c, 0); if (c->isfloating) c->float_geom = c->geom; - if (selmon->isoverview) { - Arg arg = {0}; - toggleoverview(&arg); - } - maxmizescreen_box.x = c->mon->w.x + gappoh; - maxmizescreen_box.y = c->mon->w.y + gappov; - maxmizescreen_box.width = c->mon->w.width - 2 * gappoh; - maxmizescreen_box.height = c->mon->w.height - 2 * gappov; + maximizescreen_box.x = c->mon->w.x + gappoh; + maximizescreen_box.y = c->mon->w.y + gappov; + maximizescreen_box.width = c->mon->w.width - 2 * gappoh; + maximizescreen_box.height = c->mon->w.height - 2 * gappov; wlr_scene_node_raise_to_top(&c->scene->node); // 将视图提升到顶层 - resize(c, maxmizescreen_box, 0); - c->ismaxmizescreen = 1; + if (!is_scroller_layout(c->mon) || c->isfloating) + resize(c, maximizescreen_box, 0); + c->ismaximizescreen = 1; } else { c->bw = c->isnoborder ? 0 : borderpx; - c->ismaxmizescreen = 0; + c->ismaximizescreen = 0; if (c->isfloating) setfloating(c, 1); } - wlr_scene_node_reparent(&c->scene->node, layers[maxmizescreen ? LyrTile - : c->isfloating ? LyrTop - : LyrTile]); - if (!c->ismaxmizescreen) { + wlr_scene_node_reparent(&c->scene->node, + layers[c->isfloating ? LyrTop : LyrTile]); + if (!c->ismaximizescreen) { set_size_per(c->mon, c); } - if (!c->force_maximize && !c->ismaxmizescreen) { + if (!c->force_maximize && !c->ismaximizescreen) { client_set_maximized(c, false); - } else { + } else if (!c->force_maximize && c->ismaximizescreen) { client_set_maximized(c, true); } @@ -4479,29 +4667,29 @@ void setfakefullscreen(Client *c, int fakefullscreen) { void setfullscreen(Client *c, int fullscreen) // 用自定义全屏代理自带全屏 { - c->isfullscreen = fullscreen; if (!c || !c->mon || !client_surface(c)->mapped || c->iskilling) return; + if (c->mon->isoverview) + return; + + c->isfullscreen = fullscreen; + client_set_fullscreen(c, fullscreen); if (fullscreen) { - if (c->ismaxmizescreen) - setmaxmizescreen(c, 0); + if (c->ismaximizescreen) + setmaximizescreen(c, 0); if (c->isfloating) c->float_geom = c->geom; - if (selmon->isoverview) { - Arg arg = {0}; - toggleoverview(&arg); - } c->bw = 0; wlr_scene_node_raise_to_top(&c->scene->node); // 将视图提升到顶层 - resize(c, c->mon->m, 1); + if (!is_scroller_layout(c->mon) || c->isfloating) + resize(c, c->mon->m, 1); c->isfullscreen = 1; - // c->isfloating = 0; } else { c->bw = c->isnoborder ? 0 : borderpx; c->isfullscreen = 0; @@ -4563,38 +4751,37 @@ void reset_keyboard_layout(void) { return; } - // Get layout abbreviations - const char **layout_ids = calloc(num_layouts, sizeof(char *)); - if (!layout_ids) { - wlr_log(WLR_ERROR, "Failed to allocate layout IDs"); + // 现在安全地创建真正的keymap + struct xkb_keymap *new_keymap = xkb_keymap_new_from_names( + context, &xkb_rules, XKB_KEYMAP_COMPILE_NO_FLAGS); + if (!new_keymap) { + // 理论上这里不应该失败,因为前面已经验证过了 + wlr_log(WLR_ERROR, + "Unexpected failure to create keymap after validation"); goto cleanup_context; } - for (int i = 0; i < num_layouts; i++) { - layout_ids[i] = - get_layout_abbr(xkb_keymap_layout_get_name(keyboard->keymap, i)); - if (!layout_ids[i]) { - wlr_log(WLR_ERROR, "Failed to get layout abbreviation"); - goto cleanup_layouts; - } + // 验证新keymap是否有布局 + const int new_num_layouts = xkb_keymap_num_layouts(new_keymap); + if (new_num_layouts < 1) { + wlr_log(WLR_ERROR, "New keymap has no layouts"); + xkb_keymap_unref(new_keymap); + goto cleanup_context; } - // Keep the same rules but just reapply them - struct xkb_rule_names rules = xkb_rules; - - // Create new keymap with current rules - struct xkb_keymap *new_keymap = - xkb_keymap_new_from_names(context, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS); - if (!new_keymap) { - wlr_log(WLR_ERROR, "Failed to create keymap for layouts: %s", - rules.layout); - goto cleanup_layouts; + // 确保当前布局索引在新keymap中有效 + if (current >= new_num_layouts) { + wlr_log(WLR_INFO, + "Current layout index %u out of range for new keymap, " + "resetting to 0", + current); + current = 0; } - // Apply the same keymap (this will reset the layout state) - unsigned int depressed = keyboard->modifiers.depressed; - unsigned int latched = keyboard->modifiers.latched; - unsigned int locked = keyboard->modifiers.locked; + // Apply the new keymap + uint32_t depressed = keyboard->modifiers.depressed; + uint32_t latched = keyboard->modifiers.latched; + uint32_t locked = keyboard->modifiers.locked; wlr_keyboard_set_keymap(keyboard, new_keymap); @@ -4605,17 +4792,31 @@ void reset_keyboard_layout(void) { wlr_seat_set_keyboard(seat, keyboard); wlr_seat_keyboard_notify_modifiers(seat, &keyboard->modifiers); + InputDevice *id; + wl_list_for_each(id, &inputdevices, link) { + if (id->wlr_device->type != WLR_INPUT_DEVICE_KEYBOARD) { + continue; + } + + struct wlr_keyboard *tkb = (struct wlr_keyboard *)id->device_data; + + wlr_keyboard_set_keymap(tkb, keyboard->keymap); + wlr_keyboard_notify_modifiers(tkb, depressed, latched, locked, 0); + tkb->modifiers.group = 0; + + // 7. 更新 seat + wlr_seat_set_keyboard(seat, tkb); + wlr_seat_keyboard_notify_modifiers(seat, &tkb->modifiers); + } + // Cleanup xkb_keymap_unref(new_keymap); -cleanup_layouts: - free(layout_ids); - cleanup_context: xkb_context_unref(context); } -void setmon(Client *c, Monitor *m, unsigned int newtags, bool focus) { +void setmon(Client *c, Monitor *m, uint32_t newtags, bool focus) { Monitor *oldmon = c->mon; if (oldmon == m) @@ -4644,7 +4845,7 @@ void setmon(Client *c, Monitor *m, unsigned int newtags, bool focus) { setfullscreen(c, c->isfullscreen); /* This will call arrange(c->mon) */ } - if (focus) { + if (focus && !client_is_x11_popup(c)) { focusclient(focustop(selmon), 1); } @@ -4685,15 +4886,18 @@ void setsel(struct wl_listener *listener, void *data) { } void show_hide_client(Client *c) { + uint32_t target = 1; + + set_size_per(c->mon, c); + target = get_tags_first_tag(c->oldtags); - unsigned int target = get_tags_first_tag(c->oldtags); if (!c->is_in_scratchpad) { tag_client(&(Arg){.ui = target}, c); } else { c->tags = c->oldtags; arrange(c->mon, false); } - c->isminied = 0; + c->isminimized = 0; wlr_foreign_toplevel_handle_v1_set_minimized(c->foreign_toplevel, false); focusclient(c, 1); wlr_foreign_toplevel_handle_v1_set_activated(c->foreign_toplevel, true); @@ -4720,6 +4924,20 @@ void create_output(struct wlr_backend *backend, void *data) { #endif } +// 修改信号处理函数,接收掩码参数 +void handle_print_status(struct wl_listener *listener, void *data) { + + Monitor *m = NULL; + wl_list_for_each(m, &mons, link) { + if (!m->wlr_output->enabled) { + continue; + } + dwl_ext_workspace_printstatus(m); + + dwl_ipc_output_printstatus(m); + } +} + void setup(void) { setenv("XCURSOR_SIZE", "24", 1); @@ -4740,16 +4958,14 @@ void setup(void) { * clients from the Unix socket, manging Wayland globals, and so on. */ dpy = wl_display_create(); event_loop = wl_display_get_event_loop(dpy); - pointer_manager = wlr_relative_pointer_manager_v1_create(dpy); - tablet_mgr = wlr_tablet_v2_create(dpy); - /* The backend is a wlroots feature which abstracts the underlying input and - * output hardware. The autocreate option will choose the most suitable - * backend based on the current environment, such as opening an X11 window - * if an X11 server is running. The NULL argument here optionally allows you - * to pass in a custom renderer if wlr_renderer doesn't meet your needs. The - * backend uses the renderer, for example, to fall back to software cursors - * if the backend does not support hardware cursors (some older GPUs - * don't). */ + /* The backend is a wlroots feature which abstracts the underlying input + * and output hardware. The autocreate option will choose the most + * suitable backend based on the current environment, such as opening an + * X11 window if an X11 server is running. The NULL argument here + * optionally allows you to pass in a custom renderer if wlr_renderer + * doesn't meet your needs. The backend uses the renderer, for example, + * to fall back to software cursors if the backend does not support + * hardware cursors (some older GPUs don't). */ if (!(backend = wlr_backend_autocreate(event_loop, &session))) die("couldn't create backend"); @@ -4817,6 +5033,10 @@ void setup(void) { wlr_alpha_modifier_v1_create(dpy); wlr_ext_data_control_manager_v1_create(dpy, 1); + // 在 setup 函数中 + wl_signal_init(&mango_print_status); + wl_signal_add(&mango_print_status, &print_status_listener); + /* Initializes the interface used to implement urgency hints */ activation = wlr_xdg_activation_v1_create(dpy); wl_signal_add(&activation->events.request_activate, &request_activate); @@ -4827,6 +5047,10 @@ void setup(void) { power_mgr = wlr_output_power_manager_v1_create(dpy); wl_signal_add(&power_mgr->events.set_mode, &output_power_mgr_set_mode); + tearing_control = wlr_tearing_control_manager_v1_create(dpy, 1); + tearing_new_object.notify = handle_tearing_new_object; + wl_signal_add(&tearing_control->events.new_object, &tearing_new_object); + /* Creates an output layout, which a wlroots utility for working with an * arrangement of screens in a physical layout. */ output_layout = wlr_output_layout_create(dpy); @@ -4936,6 +5160,7 @@ void setup(void) { * to let us know when new input devices are available on the backend. */ wl_list_init(&inputdevices); + wl_list_init(&keyboard_shortcut_inhibitors); wl_signal_add(&backend->events.new_input, &new_input_device); virtual_keyboard_mgr = wlr_virtual_keyboard_manager_v1_create(dpy); wl_signal_add(&virtual_keyboard_mgr->events.new_virtual_keyboard, @@ -4965,6 +5190,10 @@ void setup(void) { kb_group = createkeyboardgroup(); wl_list_init(&kb_group->destroy.link); + keyboard_shortcuts_inhibit = wlr_keyboard_shortcuts_inhibit_v1_create(dpy); + wl_signal_add(&keyboard_shortcuts_inhibit->events.new_inhibitor, + &keyboard_shortcuts_inhibit_new_inhibitor); + output_mgr = wlr_output_manager_v1_create(dpy); wl_signal_add(&output_mgr->events.apply, &output_mgr_apply); wl_signal_add(&output_mgr->events.test, &output_mgr_test); @@ -4980,6 +5209,14 @@ void setup(void) { dwl_input_method_relay = dwl_im_relay_create(); + drm_lease_manager = wlr_drm_lease_v1_manager_create(dpy, backend); + if (drm_lease_manager) { + wl_signal_add(&drm_lease_manager->events.request, &drm_lease_request); + } else { + wlr_log(WLR_DEBUG, "Failed to create wlr_drm_lease_device_v1."); + wlr_log(WLR_INFO, "VR will not be available."); + } + wl_global_create(dpy, &zdwl_ipc_manager_v2_interface, 2, NULL, dwl_ipc_manager_bind); @@ -5045,11 +5282,15 @@ void tag_client(const Arg *arg, Client *target_client) { void overview(Monitor *m) { grid(m); } // 目标窗口有其他窗口和它同个tag就返回0 -unsigned int want_restore_fullscreen(Client *target_client) { +uint32_t want_restore_fullscreen(Client *target_client) { Client *c = NULL; wl_list_for_each(c, &clients, link) { if (c && c != target_client && c->tags == target_client->tags && - c == selmon->sel) { + c == selmon->sel && + c->mon->pertag->ltidxs[get_tags_first_tag_num(c->tags)]->id != + SCROLLER && + c->mon->pertag->ltidxs[get_tags_first_tag_num(c->tags)]->id != + VERTICAL_SCROLLER) { return 0; } } @@ -5061,7 +5302,7 @@ unsigned int want_restore_fullscreen(Client *target_client) { void overview_backup(Client *c) { c->overview_isfloatingbak = c->isfloating; c->overview_isfullscreenbak = c->isfullscreen; - c->overview_ismaxmizescreenbak = c->ismaxmizescreen; + c->overview_ismaximizescreenbak = c->ismaximizescreen; c->overview_isfullscreenbak = c->isfullscreen; c->animation.tagining = false; c->animation.tagouted = false; @@ -5071,9 +5312,9 @@ void overview_backup(Client *c) { if (c->isfloating) { c->isfloating = 0; } - if (c->isfullscreen || c->ismaxmizescreen) { + if (c->isfullscreen || c->ismaximizescreen) { c->isfullscreen = 0; // 清除窗口全屏标志 - c->ismaxmizescreen = 0; + c->ismaximizescreen = 0; } c->bw = c->isnoborder ? 0 : borderpx; } @@ -5082,10 +5323,10 @@ void overview_backup(Client *c) { void overview_restore(Client *c, const Arg *arg) { c->isfloating = c->overview_isfloatingbak; c->isfullscreen = c->overview_isfullscreenbak; - c->ismaxmizescreen = c->overview_ismaxmizescreenbak; + c->ismaximizescreen = c->overview_ismaximizescreenbak; c->overview_isfloatingbak = 0; c->overview_isfullscreenbak = 0; - c->overview_ismaxmizescreenbak = 0; + c->overview_ismaximizescreenbak = 0; c->geom = c->overview_backup_geom; c->bw = c->overview_backup_bw; c->animation.tagining = false; @@ -5094,14 +5335,14 @@ void overview_restore(Client *c, const Arg *arg) { if (c->isfloating) { // XRaiseWindow(dpy, c->win); // 提升悬浮窗口到顶层 resize(c, c->overview_backup_geom, 0); - } else if (c->isfullscreen || c->ismaxmizescreen) { - if (want_restore_fullscreen(c) && c->ismaxmizescreen) { - setmaxmizescreen(c, 1); + } else if (c->isfullscreen || c->ismaximizescreen) { + if (want_restore_fullscreen(c) && c->ismaximizescreen) { + setmaximizescreen(c, 1); } else if (want_restore_fullscreen(c) && c->isfullscreen) { setfullscreen(c, 1); } else { c->isfullscreen = 0; - c->ismaxmizescreen = 0; + c->ismaximizescreen = 0; setfullscreen(c, false); } } else { @@ -5168,7 +5409,7 @@ void unmapnotify(struct wl_listener *listener, void *data) { Monitor *m = NULL; c->iskilling = 1; - if (animations && !c->is_clip_to_hide && !c->isminied && + if (animations && !c->is_clip_to_hide && !c->isminimized && (!c->mon || VISIBLEON(c, c->mon))) init_fadeout_client(c); @@ -5231,7 +5472,7 @@ void unmapnotify(struct wl_listener *listener, void *data) { } if (c->swallowedby) { - setmaxmizescreen(c->swallowedby, c->ismaxmizescreen); + setmaximizescreen(c->swallowedby, c->ismaximizescreen); setfullscreen(c->swallowedby, c->isfullscreen); c->swallowedby->swallowing = NULL; c->swallowedby = NULL; @@ -5349,11 +5590,6 @@ void updatemons(struct wl_listener *listener, void *data) { if ((c = focustop(m)) && c->isfullscreen) resize(c, m->m, 0); - /* Try to re-set the gamma LUT when updating monitors, - * it's only really needed when enabling a disabled output, but meh. - */ - m->gamma_lut_changed = 1; - config_head->state.x = m->m.x; config_head->state.y = m->m.y; @@ -5413,16 +5649,16 @@ urgent(struct wl_listener *listener, void *data) { view_in_mon(&(Arg){.ui = c->tags}, true, c->mon, true); focusclient(c, 1); } else if (c != focustop(selmon)) { - if (client_surface(c)->mapped) - client_set_border_color(c, urgentcolor); c->isurgent = 1; + if (client_surface(c)->mapped) + setborder_color(c); printstatus(); } } void view_in_mon(const Arg *arg, bool want_animation, Monitor *m, bool changefocus) { - unsigned int i, tmptag; + uint32_t i, tmptag; if (!m || (arg->ui != (~0 & TAGMASK) && m->isoverview)) { return; @@ -5433,9 +5669,9 @@ void view_in_mon(const Arg *arg, bool want_animation, Monitor *m, } if (arg->ui == UINT32_MAX) { - m->pertag->prevtag = m->tagset[m->seltags]; + m->pertag->prevtag = get_tags_first_tag_num(m->tagset[m->seltags]); m->seltags ^= 1; /* toggle sel tagset */ - m->pertag->curtag = m->tagset[m->seltags]; + m->pertag->curtag = get_tags_first_tag_num(m->tagset[m->seltags]); goto toggleseltags; } @@ -5489,6 +5725,56 @@ void view(const Arg *arg, bool want_animation) { } } +static void +handle_keyboard_shortcuts_inhibitor_destroy(struct wl_listener *listener, + void *data) { + KeyboardShortcutsInhibitor *inhibitor = + wl_container_of(listener, inhibitor, destroy); + + wlr_log(WLR_DEBUG, "Removing keyboard shortcuts inhibitor"); + + wl_list_remove(&inhibitor->link); + wl_list_remove(&inhibitor->destroy.link); + free(inhibitor); +} + +void handle_keyboard_shortcuts_inhibit_new_inhibitor( + struct wl_listener *listener, void *data) { + + struct wlr_keyboard_shortcuts_inhibitor_v1 *inhibitor = data; + + if (allow_shortcuts_inhibit == SHORTCUTS_INHIBIT_DISABLE) { + return; + } + + // per-view, seat-agnostic config via criteria + Client *c = NULL; + LayerSurface *l = NULL; + + int type = toplevel_from_wlr_surface(inhibitor->surface, &c, &l); + + if (type < 0) + return; + + if (type != LayerShell && c && !c->allow_shortcuts_inhibit) { + return; + } + + wlr_log(WLR_DEBUG, "Adding keyboard shortcuts inhibitor"); + + KeyboardShortcutsInhibitor *kbsinhibitor = + calloc(1, sizeof(KeyboardShortcutsInhibitor)); + + kbsinhibitor->inhibitor = inhibitor; + + kbsinhibitor->destroy.notify = handle_keyboard_shortcuts_inhibitor_destroy; + wl_signal_add(&inhibitor->events.destroy, &kbsinhibitor->destroy); + + wl_list_insert(&keyboard_shortcut_inhibitors, &kbsinhibitor->link); + + wlr_keyboard_shortcuts_inhibitor_v1_activate(inhibitor); +} + void virtualkeyboard(struct wl_listener *listener, void *data) { struct wlr_virtual_keyboard_v1 *kb = data; /* virtual keyboards shouldn't share keyboard group */ @@ -5541,8 +5827,8 @@ void activatex11(struct wl_listener *listener, void *data) { if (c && c->swallowing) return; - if (c->isminied) { - c->isminied = 0; + if (c->isminimized) { + c->isminimized = 0; c->tags = c->mini_restore_tag; c->is_scratchpad_show = 0; c->is_in_scratchpad = 0; @@ -5564,7 +5850,7 @@ void activatex11(struct wl_listener *listener, void *data) { } else if (c != focustop(selmon)) { c->isurgent = 1; if (client_surface(c)->mapped) - client_set_border_color(c, urgentcolor); + setborder_color(c); } if (need_arrange) { @@ -5646,7 +5932,7 @@ void sethints(struct wl_listener *listener, void *data) { printstatus(); if (c->isurgent && surface && surface->mapped) - client_set_border_color(c, urgentcolor); + setborder_color(c); } void xwaylandready(struct wl_listener *listener, void *data) { @@ -5676,13 +5962,15 @@ int main(int argc, char *argv[]) { char *startup_cmd = NULL; int c; - while ((c = getopt(argc, argv, "s:hdv")) != -1) { + while ((c = getopt(argc, argv, "s:c:hdv")) != -1) { if (c == 's') startup_cmd = optarg; else if (c == 'd') log_level = WLR_DEBUG; else if (c == 'v') die("mango " VERSION); + else if (c == 'c') + cli_config_path = optarg; else goto usage; } @@ -5700,5 +5988,5 @@ int main(int argc, char *argv[]) { return EXIT_SUCCESS; usage: - die("Usage: %s [-v] [-d] [-s startup command]", argv[0]); + die("Usage: %s [-v] [-d] [-c config file] [-s startup command]", argv[0]); }