From d3f30bad3c8ab68c0eb608cbb62a7cc5994832e9 Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Sun, 28 Jun 2020 19:08:37 -0400 Subject: [PATCH] fullscreen new windows and focus them --- src/nimwin.nim | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/nimwin.nim b/src/nimwin.nim index 01295f2..06b89c3 100644 --- a/src/nimwin.nim +++ b/src/nimwin.nim @@ -6,6 +6,7 @@ var root : TWindow proc handleBadWindow(display : PDisplay, ev : PXErrorEvent) : cint {.cdecl.} = # resourceID maps to the Window's XID # ev.resourceID + echo "Bad window", ": ", ev.resourceid 0 proc handleIOError(display : PDisplay) : cint {.cdecl.} = @@ -140,6 +141,11 @@ proc getAttributes(display : PDisplay, window : PWindow) : Option[TXWindowAttrib return none(TXWindowAttributes) return some(attrs) +proc changeEvMask(display : PDisplay, window : PWindow, eventMask : clong) = + var attributes : TXSetWindowAttributes + attributes.eventMask = eventMask + discard display.XChangeWindowAttributes(window[], CWEventMask, attributes.addr) + iterator getChildren(display : PDisplay) : Window = var currentWindow : PWindow var rootReturn : TWindow @@ -299,6 +305,8 @@ when isMainModule: root = DefaultRootWindow(display) + display.changeEvMask(root.addr, SubstructureNotifyMask or StructureNotifyMask or ExposureMask) + display.grabKeyCombo(XK_Return, @[ShiftMask.cuint]) display.grabKeyCombo(XK_T, @[ShiftMask.cuint]) display.grabKeyCombo(XK_Tab) # Cycle through windows @@ -352,6 +360,7 @@ when isMainModule: let windowStack = filter(toSeq(getChildren(display)), (w) => not w.props.anyIt(it.name.in(ignored))) if windowStack.len > 0: + echo "Tab cycling shit, raising this window: ", windowStack[0].win discard display.XSetInputFocus(windowStack[0].win, RevertToPointerRoot, CurrentTime) discard display.XRaiseWindow(windowStack[0].win) @@ -406,6 +415,27 @@ when isMainModule: discard XGetWindowAttributes(display, ev.xButton.subWindow, attr.addr) start = ev.xButton + elif (ev.theType == CreateNotify) and (ev.xcreatewindow.parent == root): + let rootAttrs = getAttributes(display, root.addr) + if rootAttrs.isSome: + let struts = display.calculateStruts + let screenHeight = rootAttrs.get.height + let screenWidth = rootAttrs.get.width + + let winAttrs : Option[TXWindowAttributes] = getAttributes(display, ev.xcreatewindow.window.addr) + + let depth = winAttrs.get.borderWidth.cuint + let borderWidth = winAttrs.get.depth.cuint + + if winAttrs.isSome and winAttrs.get.overrideRedirect == 0: + discard XMoveResizeWindow(display, + ev.xcreatewindow.window, + 0, struts.top.cint, + screenWidth.cuint, screenHeight.cuint - struts.bottom.cuint - borderWidth.cuint) + + elif (ev.theType == MapNotify) and (ev.xmap.overrideRedirect == 0): + discard display.XSetInputFocus(ev.xmap.window, RevertToPointerRoot, CurrentTime) + elif (ev.theType == MotionNotify) and (start.subWindow != None): # Discard any following MotionNotify events