Skip to content

Commit 5307384

Browse files
author
user
committed
add support for focus-mode
1 parent 25d87d5 commit 5307384

7 files changed

Lines changed: 28 additions & 5 deletions

File tree

docs/wormc.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,7 @@ Sets the path for the appropriate button for inactive windows only, when being h
103103
Takes a modifier (defined in, eg, X11/X.h) and sets it as the default for moving/resizing windows. Examples:
104104
1 << 3 = Mod1Mask = Alt = 8
105105
1 << 6 = Mod4Mask = Super/Mod/Win = 64
106+
### `focus-mode(int)`
107+
Sets the focus mode.
108+
1: is focus-follows-click (like Microsoft Windows).
109+
2: is the traditional X11 focus-follows-mouse.

src/atoms.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ type
9191
IpcMaximizeClient = "WORM_IPC_MAXIMIZE_CLIENT",
9292
IpcMinimizeClient = "WORM_IPC_MINIMIZE_CLIENT",
9393
IpcDecorationDisable = "WORM_IPC_DECORATION_DISABLE",
94+
IpcFocusMode = "WORM_IPC_FOCUS_MODE",
9495
IpcModifier = "WORM_IPC_MODIFIER"
9596

9697
func getNetAtoms*(dpy: ptr Display): array[NetAtom, Atom] =

src/events/clientmessage.nim

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,4 +693,8 @@ proc handleClientMessage*(self: var Wm; ev: XClientMessageEvent) =
693693
None,
694694
None
695695
)
696-
696+
elif ev.data.l[0] == clong self.ipcAtoms[IpcFocusMode]:
697+
if ev.data.l[1] == 1:
698+
self.focusMode = FocusFollowsClick
699+
else:
700+
self.focusMode = FocusFollowsMouse

src/events/enternotify.nim

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import ../wm, ../types
2-
import x11/xlib
3-
# import std/options
2+
import x11/xlib, x11/x
3+
import std/options
44

55
proc handleEnterNotify*(self: var Wm; ev: XEnterWindowEvent): void =
66
for client in self.clients.mitems:
@@ -16,4 +16,13 @@ proc handleEnterNotify*(self: var Wm; ev: XEnterWindowEvent): void =
1616
client.frame.minimizeHovered = true
1717
self.renderTop client
1818
break
19-
19+
if self.focusMode == FocusFollowsMouse:
20+
let clientOpt = self.findClient do (client: Client) ->
21+
bool: client.frame.window == ev.window or client.frame.window == ev.subwindow
22+
if clientOpt.isNone: return
23+
let client = clientOpt.get[0]
24+
discard self.dpy.XRaiseWindow client.frame.window
25+
discard self.dpy.XSetInputFocus(client.window, RevertToPointerRoot, CurrentTime)
26+
discard self.dpy.XMapWindow client.frame.window
27+
self.focused = some clientOpt.get[1]
28+
self.raiseClient clientOpt.get[0][]

src/types.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ type
4949
closePaths*, minimizePaths*, maximizePaths*: ButtonPaths
5050
modifier*: uint32
5151
TagSet* = array[9, bool] # distinct
52+
FocusMode* = enum
53+
FocusFollowsClick, FocusFollowsMouse
5254

5355
proc defaultTagSet*: TagSet = [true, false, false, false, false, false, false,
5456
false, false] # put the user on tag 1 when the wm starts.

src/wm.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type
2525
tags*: TagSet
2626
layout*: Layout
2727
noDecorList*: seq[Regex]
28+
focusMode*: FocusMode
2829

2930
proc initWm*(): Wm =
3031
let dpy = XOpenDisplay nil
@@ -165,6 +166,7 @@ proc initWm*(): Wm =
165166
tags: defaultTagSet(),
166167
layout: lyFloating,
167168
noDecorList: @[],
169+
focusMode: FocusFollowsClick
168170
)
169171

170172
func findClient*(

src/wormc.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ proc main() =
185185
data = ipcAtoms[IpcMinimizeClient].formatMess()
186186
of "modifier":
187187
data = ipcAtoms[IpcModifier].formatMess(params[i+1])
188-
188+
of "focus-mode":
189+
data = ipcAtoms[IpcFocusMode].formatMess(params[i+1])
189190

190191
else: discard
191192

0 commit comments

Comments
 (0)