├── LICENSE ├── README.md ├── nimWM.nimble └── src └── nimwm.nim /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Shuu.N 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nimWM 2 | Simple window manager written in nim 3 | -------------------------------------------------------------------------------- /nimWM.nimble: -------------------------------------------------------------------------------- 1 | # Package 2 | 3 | version = "0.0.2" 4 | author = "fox0430" 5 | description = "simple window manager" 6 | license = "MIT" 7 | srcDir = "src" 8 | bin = @["nimwm"] 9 | 10 | # Dependencies 11 | 12 | requires "x11 >= 1.0" 13 | -------------------------------------------------------------------------------- /src/nimwm.nim: -------------------------------------------------------------------------------- 1 | import x11/xlib, x11/x 2 | converter toCint(x: TKeyCode): cint = x.cint 3 | converter int32toCUint(x: int32): cuint = x.cuint 4 | converter toTBool(x: bool): TBool = x.TBool 5 | converter toBool(x: TBool): bool = x.bool 6 | 7 | type XWindowInfo = object 8 | display*: PDisplay 9 | attr*: TXWindowAttributes 10 | start*: TXButtonEvent 11 | ev*: TXEvent 12 | 13 | proc initXWIndowInfo(winInfo: var XWindowInfo): XWIndowInfo = 14 | winInfo.display = XOpenDisplay(nil) 15 | if winInfo.display == nil: 16 | quit "Failed to open display" 17 | 18 | discard XGrabKey(winInfo.display, XKeysymToKeycode(winInfo.display, XStringToKeysym("F1")), Mod1Mask, 19 | DefaultRootWindow(winInfo.display), true, GrabModeAsync, GrabModeAsync) 20 | discard XGrabButton(winInfo.display, 1, Mod1Mask, DefaultRootWindow(winInfo.display), true, 21 | ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None) 22 | discard XGrabButton(winInfo.display, 3, Mod1Mask, DefaultRootWindow(winInfo.display), true, 23 | ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None) 24 | 25 | winInfo.start.subwindow = None 26 | 27 | return winInfo 28 | 29 | when isMainModule: 30 | 31 | var winInfo: XWindowInfo 32 | 33 | winInfo = initXWIndowInfo(winInfo) 34 | 35 | while true: 36 | discard XNextEvent(winInfo.display, winInfo.ev.addr) 37 | 38 | if winInfo.ev.theType == KeyPress: 39 | var kev = cast[PXKeyEvent](winInfo.ev.addr)[] 40 | if not kev.subwindow.addr.isNil: 41 | discard XLowerWindow(winInfo.display, kev.subwindow) 42 | 43 | elif winInfo.ev.theType == ButtonPress: 44 | var bev = cast[PXButtonEvent](winInfo.ev.addr)[] 45 | if not bev.subwindow.addr.isNil: 46 | discard XGrabPointer(winInfo.display, bev.subwindow, true, 47 | PointerMotionMask or ButtonReleaseMask, GrabModeAsync, 48 | GrabModeAsync, None, None, CurrentTime) 49 | discard XGetWindowAttributes(winInfo.display, bev.subwindow, winInfo.attr.addr); 50 | winInfo.start = bev; 51 | elif winInfo.ev.theType == MotionNotify: 52 | var mnev = cast[PXMotionEvent](winInfo.ev.addr)[] 53 | var bev = cast[PXButtonEvent](winInfo.ev.addr)[] 54 | while XCheckTypedEvent(winInfo.display, MotionNotify, winInfo.ev.addr): 55 | continue 56 | var 57 | xdiff = bev.x_root - winInfo.start.x_root 58 | ydiff = bev.y_root - winInfo.start.y_root 59 | discard XMoveResizeWindow(winInfo.display, mnev.window, 60 | winInfo.attr.x + (if winInfo.start.button==1: xdiff else: 0), 61 | winInfo.attr.y + (if winInfo.start.button==1: ydiff else: 0), 62 | max(1, winInfo.attr.width + (if winInfo.start.button==3: xdiff else: 0)), 63 | max(1, winInfo.attr.height + (if winInfo.start.button==3: ydiff else: 0))) 64 | 65 | elif winInfo.ev.theType == ButtonRelease: 66 | discard XUngrabPointer(winInfo.display, CurrentTime) 67 | else: 68 | continue 69 | --------------------------------------------------------------------------------