Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 75 additions & 91 deletions src/atoms.nim
Original file line number Diff line number Diff line change
@@ -1,100 +1,84 @@
import x11/[xlib, x]
import
x11/[xlib, x ]

converter toXBool(x: bool): XBool = x.XBool
converter toBool(x: XBool): bool = x.bool

type
NetAtom* = enum
NetActiveWindow, NetSupported,
NetSystemTray, NetSystemTrayOP, NetSystemTrayOrientation,
NetSystemTrayOrientationHorz,
NetWMName, NetWMState, NetWMStateAbove, NetWMStateMaximizedVert, NetWMStateMaximizedHorz, NetWMStateSticky, NetWMStateModal,
NetSupportingWMCheck, NetWMStateFullScreen, NetClientList,
NetWMStrutPartial,
NetWMWindowType, NetWMWindowTypeNormal, NetWMWindowTypeDialog,
NetWMWindowTypeUtility,
NetWMWindowTypeToolbar, NetWMWindowTypeSplash, NetWMWindowTypeMenu,
NetWMWindowTypeDropdownMenu, NetWMWindowTypePopupMenu,
NetWMWindowTypeTooltip,
NetWMWindowTypeNotification, NetWMWindowTypeDock, NetWMWindowTypeDesktop,
NetWMDesktop, NetDesktopViewport, NetNumberOfDesktops, NetCurrentDesktop,
NetDesktopNames, NetFrameExtents
NetActiveWindow = "_NET_ACTIVE_WINDOW",
NetSupported = "_NET_SUPPORTED",
NetSystemTray = "_NET_SYSTEM_TRAY_S0",
NetSystemTrayOP = "_NET_SYSTEM_TRAY_OPCODE",
NetSystemTrayOrientation = "_NET_SYSTEM_TRAY_ORIENTATION",
NetSystemTrayOrientationHorz = "_NET_SYSTEM_TRAY_ORIENTATION_HORZ",
NetWMName = "_NET_WM_NAME",
NetWMState = "_NET_WM_STATE",
NetWMStateAbove = "_NET_WM_STATE_ABOVE",
NetWMStateMaximizedVert = "_NET_WM_STATE_MAXIMIZED_VERT",
NetWMStateMaximizedHorz = "_NET_WM_STATE_MAXIMIZED_HORZ",
NetWMStateSticky = "_NET_WM_STATE_STICKY",
NetWMStateModal = "_NET_WM_STATE_MODAL",
NetSupportingWMCheck = "_NET_SUPPORTING_WM_CHECK",
NetWMStateFullScreen = "_NET_WM_STATE_FULLSCREEN",
NetClientList = "_NET_CLIENT_LIST",
NetWMStrutPartial = "_NET_WM_STRUT_PARTIAL",
NetWMWindowType = "_NET_WM_WINDOW_TYPE",
NetWMWindowTypeNormal = "_NET_WM_WINDOW_TYPE_NORMAL",
NetWMWindowTypeDialog = "_NET_WM_WINDOW_TYPE_DIALOG",
NetWMWindowTypeUtility = "_NET_WM_WINDOW_TYPE_UTILITY",
NetWMWindowTypeToolbar = "_NET_WM_WINDOW_TYPE_TOOLBAR",
NetWMWindowTypeSplash = "_NET_WM_WINDOW_TYPE_SPLASH",
NetWMWindowTypeMenu = "_NET_WM_WINDOW_TYPE_MENU",
NetWMWindowTypeDropdownMenu = "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU",
NetWMWindowTypePopupMenu = "_NET_WM_WINDOW_TYPE_POPUP_MENU",
NetWMWindowTypeTooltip = "_NET_WM_WINDOW_TYPE_TOOLTIP",
NetWMWindowTypeNotification = "_NET_WM_WINDOW_TYPE_NOTIFICATION",
NetWMWindowTypeDock = "_NET_WM_WINDOW_TYPE_DOCK",
NetWMWindowTypeDesktop = "_NET_WM_WINDOW_TYPE_DESKTOP",
NetWMDesktop = "_NET_WM_DESKTOP",
NetDesktopViewport = "_NET_DESKTOP_VIEWPORT",
NetNumberOfDesktops = "_NET_NUMBER_OF_DESKTOPS",
NetCurrentDesktop = "_NET_CURRENT_DESKTOP",
NetDesktopNames = "_NET_DESKTOP_NAMES",
NetFrameExtents = "_NET_FRAME_EXTENTS"

IpcAtom* = enum
IpcClientMessage, IpcBorderActivePixel, IpcBorderInactivePixel,
IpcBorderWidth, IpcFrameActivePixel, IpcFrameInactivePixel, IpcFrameHeight, IpcTextActivePixel, IpcTextInactivePixel,
IpcTextFont, IpcTextOffset, IpcKillClient, IpcCloseClient, IpcSwitchTag, IpcLayout, IpcGaps, IpcMaster, IpcStruts,
IpcMoveTag, IpcFrameLeft, IpcFrameCenter, IpcFrameRight,
IpcFloat, IpcButtonOffset, IpcButtonSize, IpcRootMenu, IpcClosePath, IpcMaximizePath, IpcMaximizeClient,
IpcDecorationDisable
IpcClientMessage = "WORM_IPC_CLIENT_MESSAGE",
IpcBorderActivePixel = "WORM_IPC_BORDER_ACTIVE_PIXEL",
IpcBorderInactivePixel = "WORM_IPC_BORDER_INACTIVE_PIXEL",
IpcBorderWidth = "WORM_IPC_BORDER_WIDTH",
IpcFrameActivePixel = "WORM_IPC_FRAME_ACTIVE_PIXEL",
IpcFrameInactivePixel = "WORM_IPC_FRAME_INACTIVE_PIXEL",
IpcFrameHeight = "WORM_IPC_FRAME_HEIGHT",
IpcTextActivePixel = "WORM_IPC_TEXT_ACTIVE_PIXEL",
IpcTextInactivePixel = "WORM_IPC_TEXT_INACTIVE_PIXEL",
IpcTextFont = "WORM_IPC_TEXT_FONT",
IpcTextOffset = "WORM_IPC_TEXT_OFFSET",
IpcKillClient = "WORM_IPC_KILL_CLIENT",
IpcCloseClient = "WORM_IPC_CLOSE_CLIENT",
IpcSwitchTag = "WORM_IPC_SWITCH_TAG",
IpcLayout = "WORM_IPC_LAYOUT",
IpcGaps = "WORM_IPC_GAPS",
IpcMaster = "WORM_IPC_MASTER",
IpcStruts = "WORM_IPC_STRUTS",
IpcMoveTag = "WORM_IPC_MOVE_TAG",
IpcFrameLeft = "WORM_IPC_FRAME_LEFT",
IpcFrameCenter = "WORM_IPC_FRAME_CENTER",
IpcFrameRight = "WORM_IPC_FRAME_RIGHT",
IpcFloat = "WORM_IPC_FLOAT",
IpcButtonOffset = "WORM_IPC_BUTTON_OFFSET",
IpcButtonSize = "WORM_IPC_BUTTON_SIZE",
IpcRootMenu = "WORM_IPC_ROOT_MENU",
IpcClosePath = "WORM_IPC_CLOSE_PATH",
IpcMaximizePath = "WORM_IPC_MAXIMIZE_PATH",
IpcMaximizeClient = "WORM_IPC_MAXIMIZE_CLIENT",
IpcDecorationDisable = "WORM_IPC_DECORATION_DISABLE"

func getNetAtoms*(dpy: ptr Display): array[NetAtom, Atom] =
[
dpy.XInternAtom("_NET_ACTIVE_WINDOW", false),
dpy.XInternAtom("_NET_SUPPORTED", false),
dpy.XInternAtom("_NET_SYSTEM_TRAY_S0", false),
dpy.XInternAtom("_NET_SYSTEM_TRAY_OPCODE", false),
dpy.XInternAtom("_NET_SYSTEM_TRAY_ORIENTATION", false),
dpy.XInternAtom("_NET_SYSTEM_TRAY_ORIENTATION_HORZ", false),
dpy.XInternAtom("_NET_WM_NAME", false),
dpy.XInternAtom("_NET_WM_STATE", false),
dpy.XInternAtom("_NET_WM_STATE_ABOVE", false),
dpy.XInternAtom("_NET_WM_STATE_MAXIMIZED_VERT", false),
dpy.XInternAtom("_NET_WM_STATE_MAXIMIZED_HORZ", false),
dpy.XInternAtom("_NET_WM_STATE_STICKY", false),
dpy.XInternAtom("_NET_WM_STATE_MODAL", false),
dpy.XInternAtom("_NET_SUPPORTING_WM_CHECK", false),
dpy.XInternAtom("_NET_WM_STATE_FULLSCREEN", false),
dpy.XInternAtom("_NET_CLIENT_LIST", false),
dpy.XInternAtom("_NET_WM_STRUT_PARTIAL", false),
dpy.XInternAtom("_NET_WM_WINDOW_TYPE", false),
dpy.XInternAtom("_NET_WM_WINDOW_TYPE_NORMAL", false),
dpy.XInternAtom("_NET_WM_WINDOW_TYPE_DIALOG", false),
dpy.XInternAtom("_NET_WM_WINDOW_TYPE_UTILITY", false),
dpy.XInternAtom("_NET_WM_WINDOW_TYPE_TOOLBAR", false),
dpy.XInternAtom("_NET_WM_WINDOW_TYPE_SPLASH", false),
dpy.XInternAtom("_NET_WM_WINDOW_TYPE_MENU", false),
dpy.XInternAtom("_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", false),
dpy.XInternAtom("_NET_WM_WINDOW_TYPE_POPUP_MENU", false),
dpy.XInternAtom("_NET_WM_WINDOW_TYPE_TOOLTIP", false),
dpy.XInternAtom("_NET_WM_WINDOW_TYPE_NOTIFICATION", false),
dpy.XInternAtom("_NET_WM_WINDOW_TYPE_DOCK", false),
dpy.XInternAtom("_NET_WM_WINDOW_TYPE_DESKTOP", false),
dpy.XInternAtom("_NET_WM_DESKTOP", false),
dpy.XInternAtom("_NET_DESKTOP_VIEWPORT", false),
dpy.XInternAtom("_NET_NUMBER_OF_DESKTOPS", false),
dpy.XInternAtom("_NET_CURRENT_DESKTOP", false),
dpy.XInternAtom("_NET_DESKTOP_NAMES", false),
dpy.XInternAtom("_NET_FRAME_EXTENTS", false)
]
for atom in NetAtom:
result[atom] = dpy.XInternAtom(($atom).cstring, false)

func getIpcAtoms*(dpy: ptr Display): array[IpcAtom, Atom] =
[
dpy.XInternAtom("WORM_IPC_CLIENT_MESSAGE", false),
dpy.XInternAtom("WORM_IPC_BORDER_ACTIVE_PIXEL", false),
dpy.XInternAtom("WORM_IPC_BORDER_INACTIVE_PIXEL", false),
dpy.XInternAtom("WORM_IPC_BORDER_WIDTH", false),
dpy.XInternAtom("WORM_IPC_FRAME_ACTIVE_PIXEL", false),
dpy.XInternAtom("WORM_IPC_FRAME_INACTIVE_PIXEL", false),
dpy.XInternAtom("WORM_IPC_FRAME_HEIGHT", false),
dpy.XInternAtom("WORM_IPC_TEXT_ACTIVE_PIXEL", false),
dpy.XInternAtom("WORM_IPC_TEXT_INACTIVE_PIXEL", false),
dpy.XInternAtom("WORM_IPC_TEXT_FONT", false),
dpy.XInternAtom("WORM_IPC_TEXT_OFFSET", false),
dpy.XInternAtom("WORM_IPC_KILL_CLIENT", false),
dpy.XInternAtom("WORM_IPC_CLOSE_CLIENT", false),
dpy.XInternAtom("WORM_IPC_SWITCH_TAG", false),
dpy.XInternAtom("WORM_IPC_LAYOUT", false),
dpy.XInternAtom("WORM_IPC_MASTER", false),
dpy.XInternAtom("WORM_IPC_GAPS", false),
dpy.XInternAtom("WORM_IPC_STRUTS", false),
dpy.XInternAtom("WORM_IPC_MOVE_TAG", false),
dpy.XInternAtom("WORM_IPC_FRAME_LEFT", false),
dpy.XInternAtom("WORM_IPC_FRAME_CENTER", false),
dpy.XInternAtom("WORM_IPC_FRAME_RIGHT", false),
dpy.XInternAtom("WORM_IPC_FLOAT", false),
dpy.XInternAtom("WORM_IPC_BUTTON_OFFSET", false),
dpy.XInternAtom("WORM_IPC_BUTTON_SIZE", false),
dpy.XInternAtom("WORM_IPC_ROOT_MENU", false),
dpy.XInternAtom("WORM_IPC_CLOSE_PATH", false),
dpy.XInternAtom("WORM_IPC_MAXIMIZE_PATH", false),
dpy.XInternAtom("WORM_IPC_MAXIMIZE_CLIENT", false),
dpy.XInternAtom("WORM_IPC_DECORATION_DISABLE", false)
]
for atom in IpcAtom:
result[atom] = dpy.XInternAtom(($atom).cstring, false)
43 changes: 43 additions & 0 deletions src/events.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import
std/[os, osproc],
x11/[x, xlib],
wm,
log,
events/[
buttonpress,
buttonrelease,
clientmessage,
configurenotify,
configurerequest,
destroynotify,
expose,
maprequest,
motionnotify,
propertynotify,
unmapnotify
]

proc dispatchEvent*(self: var Wm; ev: XEvent) =
case ev.theType:
of ButtonPress: self.handleButtonPress ev.xbutton
of ButtonRelease: self.handleButtonRelease ev.xbutton
of MotionNotify: self.handleMotionNotify ev.xmotion
of MapRequest: self.handleMapRequest ev.xmaprequest
of ConfigureRequest: self.handleConfigureRequest ev.xconfigurerequest
of ConfigureNotify: self.handleConfigureNotify ev.xconfigure
of UnmapNotify: self.handleUnmapNotify ev.xunmap
of DestroyNotify: self.handleDestroyNotify ev.xdestroywindow
of ClientMessage: self.handleClientMessage ev.xclient
of Expose: self.handleExpose ev.xexpose
of PropertyNotify: self.handlePropertyNotify ev.xproperty
else: discard

proc eventLoop*(self: var Wm) =
if fileExists expandTilde "~/.config/worm/rc":
log "config file found, loading..."
discard startProcess expandTilde "~/.config/worm/rc"
log "config file loaded!"
while true:
discard self.dpy.XNextEvent(unsafeAddr self.currEv)
self.dispatchEvent self.currEv

Loading