Skip to content

Commit 279c94b

Browse files
committed
add window rule disable deco
1 parent 49e49d6 commit 279c94b

File tree

7 files changed

+47
-8
lines changed

7 files changed

+47
-8
lines changed

src/atoms.nim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ type
2222
IpcBorderWidth, IpcFrameActivePixel, IpcFrameInactivePixel, IpcFrameHeight, IpcTextActivePixel, IpcTextInactivePixel,
2323
IpcTextFont, IpcTextOffset, IpcKillClient, IpcCloseClient, IpcSwitchTag, IpcLayout, IpcGaps, IpcMaster, IpcStruts,
2424
IpcMoveTag, IpcFrameLeft, IpcFrameCenter, IpcFrameRight,
25-
IpcFloat, IpcButtonOffset, IpcButtonSize, IpcRootMenu, IpcClosePath, IpcMaximizePath, IpcMaximizeClient
25+
IpcFloat, IpcButtonOffset, IpcButtonSize, IpcRootMenu, IpcClosePath, IpcMaximizePath, IpcMaximizeClient,
26+
IpcDecorationDisable
2627

2728
func getNetAtoms*(dpy: ptr Display): array[NetAtom, Atom] =
2829
[
@@ -92,5 +93,6 @@ func getIpcAtoms*(dpy: ptr Display): array[IpcAtom, Atom] =
9293
dpy.XInternAtom("WORM_IPC_ROOT_MENU", false),
9394
dpy.XInternAtom("WORM_IPC_CLOSE_PATH", false),
9495
dpy.XInternAtom("WORM_IPC_MAXIMIZE_PATH", false),
95-
dpy.XInternAtom("WORM_IPC_MAXIMIZE_CLIENT", false)
96+
dpy.XInternAtom("WORM_IPC_MAXIMIZE_CLIENT", false),
97+
dpy.XInternAtom("WORM_IPC_DECORATION_DISABLE", false)
9698
]

src/events/clientmessage.nim

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import ../wm, ../atoms, ../types, ../log
22
import x11/[xlib, x, xinerama, xatom, xft, xutil]
33
import std/[options, strutils]
4+
import regex
45

56
proc handleClientMessage*(self: var Wm; ev: XClientMessageEvent): void =
67
if ev.messageType == self.netAtoms[NetWMState]:
@@ -514,7 +515,7 @@ proc handleClientMessage*(self: var Wm; ev: XClientMessageEvent): void =
514515
IpcClosePath])
515516
let err = self.dpy.XmbTextPropertyToTextList(addr fontProp, cast[
516517
ptr ptr cstring](addr fontList), addr n)
517-
log "Changing root menu path to " & $fontList[0]
518+
log "Changing close path to " & $fontList[0]
518519
self.config.closePath = $fontList[0]
519520
if err >= Success and n > 0 and fontList != nil and fontList[0] != nil:
520521
XFreeStringList cast[ptr cstring](fontList)
@@ -527,8 +528,21 @@ proc handleClientMessage*(self: var Wm; ev: XClientMessageEvent): void =
527528
IpcMaximizePath])
528529
let err = self.dpy.XmbTextPropertyToTextList(addr fontProp, cast[
529530
ptr ptr cstring](addr fontList), addr n)
530-
log "Changing root menu path to " & $fontList[0]
531+
log "Changing maximize path to " & $fontList[0]
531532
self.config.maximizePath = $fontList[0]
532533
if err >= Success and n > 0 and fontList != nil and fontList[0] != nil:
533534
XFreeStringList cast[ptr cstring](fontList)
534535
discard XFree fontProp.value
536+
elif ev.data.l[0] == clong self.ipcAtoms[IpcDecorationDisable]:
537+
var fontProp: XTextProperty
538+
var fontList: ptr UncheckedArray[cstring]
539+
var n: cint
540+
discard self.dpy.XGetTextProperty(self.root, addr fontProp, self.ipcAtoms[
541+
IpcDecorationDisable])
542+
let err = self.dpy.XmbTextPropertyToTextList(addr fontProp, cast[
543+
ptr ptr cstring](addr fontList), addr n)
544+
log "Appending to decoration disable list: " & $fontList[0]
545+
self.noDecorList.add re $fontList[0]
546+
if err >= Success and n > 0 and fontList != nil and fontList[0] != nil:
547+
XFreeStringList cast[ptr cstring](fontList)
548+
discard XFree fontProp.value

src/events/maprequest.nim

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import ../wm, ../types, ../atoms, ../log
22
import std/[options, strutils]
3-
import x11/[x, xlib, xft, xatom]
3+
import x11/[x, xlib, xft, xatom, xutil]
4+
import regex
45

56
func getProperty[T](
67
dpy: ptr Display;
@@ -53,6 +54,16 @@ proc handleMapRequest*(self: var Wm; ev: XMapRequestEvent): void =
5354
if hints.isSome and hints.get.flags == 2 and hints.get.decorations == 0:
5455
frameHeight = 0
5556
csd = true
57+
var chr: XClassHint
58+
discard self.dpy.XGetClassHint(ev.window, addr chr)
59+
block:
60+
for thing in self.noDecorList:
61+
var m: RegexMatch
62+
log $chr.resClass
63+
log $thing
64+
if ($chr.resClass).match thing:
65+
csd = true
66+
frameHeight = 0
5667
var frameAttr = XSetWindowAttributes(backgroundPixel: culong self.config.frameActivePixel,
5768
borderPixel: self.config.borderActivePixel, colormap: attr.colormap)
5869
let frame = self.dpy.XCreateWindow(self.root, attr.x + self.config.struts.left.cint, attr.y + self.config.struts.top.cint,
@@ -121,7 +132,7 @@ proc handleMapRequest*(self: var Wm; ev: XMapRequestEvent): void =
121132
GrabModeSync, GrabModeSync, None, None)
122133
self.clients.add Client(window: ev.window, frame: Frame(window: frame,
123134
top: top, close: close, maximize: maximize, title: titleWin), draw: draw, color: color,
124-
title: $title, tags: self.tags, floating: self.layout == lyFloating, frameHeight: frameHeight, csd: csd)
135+
title: $title, tags: self.tags, floating: self.layout == lyFloating, frameHeight: frameHeight, csd: csd, class: $chr.resClass)
125136
self.updateClientList
126137
let extents = [self.config.borderWidth, self.config.borderWidth,
127138
self.config.borderWidth+self.config.frameHeight, self.config.borderWidth]

src/types.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type
2727
tags*: TagSet
2828
frameHeight*: uint
2929
csd*: bool
30+
class*: string
3031
Config* = object
3132
borderActivePixel*, borderInactivePixel*, borderWidth*: uint
3233
frameActivePixel*, frameInactivePixel*, frameHeight*: uint

src/wm.nim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import types
44
import atoms
55
import log
66
import pixie
7+
import regex
78
# import events/configurerequest
89

910
converter toXBool*(x: bool): XBool = x.XBool
@@ -23,6 +24,7 @@ type
2324
focused*: Option[uint]
2425
tags*: TagSet
2526
layout*: Layout
27+
noDecorList*: seq[Regex]
2628

2729
# event handlers
2830
# proc handleButtonPress(self: var Wm; ev: XButtonEvent): void
@@ -133,7 +135,7 @@ proc newWm*: Wm =
133135
textActivePixel: 0xffffff, textInactivePixel: 0x000000, textOffset: (x: uint 10, y: uint 20), gaps: 0, buttonSize: 14,
134136
struts: (top: uint 10, bottom: uint 40, left: uint 10,
135137
right: uint 10)), tags: defaultTagSet(),
136-
layout: lyFloating) # The default configuration is reasonably sane, and for now based on the Iceberg colorscheme. It may be changed later; it's recommended for users to write their own.
138+
layout: lyFloating, noDecorList: @[]) # The default configuration is reasonably sane, and for now based on the Iceberg colorscheme. It may be changed later; it's recommended for users to write their own.
137139

138140
func findClient*(self: var Wm; predicate: proc(client: Client): bool): Option[(
139141
ptr Client, uint)] =

src/wormc.nim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ proc main: void =
9393
dpy.XSetTextProperty(root, addr fontProp, ipcAtoms[IpcMaximizePath])
9494
discard XFree fontProp.value
9595
data = [clong ipcAtoms[IpcMaximizePath], 0, 0, 0, 0]
96+
of "decoration-disable": # Ditto
97+
var fontList = cstring params[i+1]
98+
var fontProp: XTextProperty
99+
discard dpy.XUtf8TextListToTextProperty(addr fontList, 1,
100+
XUTF8StringStyle, addr fontProp)
101+
dpy.XSetTextProperty(root, addr fontProp, ipcAtoms[IpcDecorationDisable])
102+
discard XFree fontProp.value
103+
data = [clong ipcAtoms[IpcDecorationDisable], 0, 0, 0, 0]
96104
of "text-offset": data = [clong ipcAtoms[IpcTextOffset],
97105
clong params[i+1].parseInt, clong params[i+2].parseInt, 0, 0]
98106
of "kill-client": data = [clong ipcAtoms[IpcKillClient], clong params[

worm.nimble

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ bin = @["worm", "wormc"]
1313
requires "nim >= 1.4.0"
1414
requires "x11"
1515
# requires "cairo" # disgusting
16-
requires "pixie"
16+
requires "pixie" # chad native Nim drawing library. lets go!
17+
requires "regex"

0 commit comments

Comments
 (0)