Fix X11 focus stealing from WM_TAKE_FOCUS apps (OnlyOffice)

This commit is contained in:
2026-03-10 16:22:35 +01:00
parent 4bce143d3e
commit 09c0acf2a7

34
i3.org
View File

@@ -72,6 +72,7 @@ workspace_layout default
* Focus Configuration
#+begin_src conf
focus_follows_mouse no
focus_on_window_activation none
#+end_src
* Settings for i3-gaps
@@ -210,10 +211,10 @@ bindsym $mod+y sticky toggle
** focus/swap
#+begin_src conf
# Focus/swap the node in the given direction
bindsym $mod+h focus left
bindsym $mod+j focus down
bindsym $mod+k focus up
bindsym $mod+l focus right
bindsym $mod+h exec --no-startup-id i3-msg focus left && i3-focus-sync
bindsym $mod+j exec --no-startup-id i3-msg focus down && i3-focus-sync
bindsym $mod+k exec --no-startup-id i3-msg focus up && i3-focus-sync
bindsym $mod+l exec --no-startup-id i3-msg focus right && i3-focus-sync
bindsym $mod+Shift+h move left
bindsym $mod+Shift+j move down
@@ -227,7 +228,7 @@ bindsym $mod+p workspace prev
bindsym $mod+n workspace next
# Focus the last Desktop
bindsym $mod+b workspace back_and_forth
bindsym $mod+b exec --no-startup-id i3-msg workspace back_and_forth && i3-focus-sync
# Focus to the given desktop
bindsym $mod+1 workspace 1
@@ -286,6 +287,29 @@ bindsym $mod+$alt+k resize shrink height 10 px or 10 ppt
bindsym $mod+$alt+l resize grow width 10 px or 10 ppt
#+end_src
* Fix focus for =WM_TAKE_FOCUS= applications
Some applications (e.g. OnlyOffice, Electron apps) use the =WM_TAKE_FOCUS= protocol and
fail to release X11 keyboard focus when i3 moves focus elsewhere.
This keybinding forces X11 focus to the window i3 currently considers focused.
#+begin_src bash :tangle ~/.local/bin/i3-focus-sync :comments none :mkdirp yes :shebang "#!/usr/bin/env bash" :tangle-mode (identity #o755)
win=$(i3-msg -t get_tree | python3 -c "
import json, sys
def find_focused(node):
if node.get('focused') and node.get('window'):
return node['window']
for child in node.get('nodes', []) + node.get('floating_nodes', []):
r = find_focused(child)
if r is not None:
return r
return None
w = find_focused(json.load(sys.stdin))
if w is not None: print(w)
" 2>/dev/null)
[ -n "$win" ] && xdotool windowfocus --sync "$win" 2>/dev/null
#+end_src
* Run Polybar and SXHKD
#+begin_src conf
# exec --no-startup-id sxhkd -m 1 -c ~/.config/sxhkd/sxhkdrc.i3