├── image.png ├── README.md ├── LICENSE └── clarawm.c /image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dacousb/clarawm/HEAD/image.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # clarawm 2 | > *a simple floating window manager* 3 | 4 | clarawm is designed to be a simple floating (with drag and drop tiling) window manager, fast and with a light and simple code base, so that anyone can understand the code. 5 | 6 | ![screenshot](image.png) 7 | 8 | ## Shortcuts (keys) 9 | 10 | The default configured modifier is Mod4 (⌘). This can be combined with the following keys to achieve different results: 11 | 12 | | | Key | Action | 13 | |---|--------|---------------| 14 | | ⌘ | Return | Open xterm | 15 | | ⌘ | d | Open dmenu | 16 | | ⌘ | q | Close window | 17 | | ⌘ | k | Kill wm | 18 | | ⌘ | MouseL | Move window | 19 | | ⌘ | MouseR | Resize window | 20 | 21 | ## To do 22 | Looking to get involved in the project or just know what do clarawm need to improve? Here it is: 23 | - Create a true tiling mode. 24 | - Try to introduce virtual workspaces. 25 | 26 | Note: clarawm is not intended to replace other window managers, I was just looking for a clean and simple manager for me. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 dacousb 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. -------------------------------------------------------------------------------- /clarawm.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details 2 | * Anyways, this software is released under the MIT license 3 | * 4 | * clarawm is designed to be a simple floating window manager, 5 | * fast and with a light and simple code base, so that 6 | * anyone can understand the code. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) 16 | 17 | Display *dpy; 18 | Screen *screen; 19 | 20 | Window root; 21 | XWindowAttributes attr; 22 | 23 | XKeyEvent key; 24 | XButtonEvent start; 25 | XEvent ev; 26 | 27 | static char *dmenu[] = {"dmenu_run", NULL}; 28 | static char *xterm[] = {"xterm", NULL}; 29 | 30 | void spawn(char **args) 31 | { 32 | if (fork() == 0) 33 | { 34 | setsid(); 35 | execvp(args[0], args); 36 | exit(EXIT_SUCCESS); 37 | } 38 | } 39 | 40 | void kill_win(Window w) 41 | { 42 | XEvent ke; 43 | ke.type = ClientMessage; 44 | ke.xclient.window = w; 45 | ke.xclient.message_type = XInternAtom(dpy, "WM_PROTOCOLS", True); 46 | ke.xclient.format = 32; 47 | ke.xclient.data.l[0] = XInternAtom(dpy, "WM_DELETE_WINDOW", True); 48 | ke.xclient.data.l[1] = CurrentTime; 49 | XSendEvent(dpy, w, False, NoEventMask, &ke); 50 | } 51 | 52 | void die(char *error) 53 | { 54 | fprintf(stderr, "clarawm: %s", error); 55 | exit(EXIT_FAILURE); 56 | } 57 | 58 | XColor color; 59 | void set_color(char *hex) 60 | { 61 | Colormap colormap = DefaultColormap(dpy, 0); 62 | XParseColor(dpy, colormap, hex, &color); 63 | XAllocColor(dpy, colormap, &color); 64 | } 65 | 66 | void borders() 67 | { 68 | unsigned int n; 69 | Window d1, d2, *wins = NULL; 70 | XQueryTree(dpy, root, &d1, &d2, &wins, &n); 71 | for (int i = 0; i < n; i++) 72 | { 73 | set_color((wins[i] == start.subwindow) ? "#1b496e" : "#7a7a7a"); 74 | XSetWindowBorder(dpy, wins[i], color.pixel); 75 | } 76 | if (wins) 77 | XFree(wins); 78 | } 79 | 80 | int main(void) 81 | { 82 | if (!(dpy = XOpenDisplay(NULL))) 83 | die("cannot open display"); 84 | 85 | root = DefaultRootWindow(dpy); 86 | screen = DefaultScreenOfDisplay(dpy); 87 | 88 | XGrabKey(dpy, XKeysymToKeycode(dpy, XK_Return), Mod4Mask, root, True, GrabModeAsync, GrabModeAsync); 89 | XGrabKey(dpy, XKeysymToKeycode(dpy, XK_D), Mod4Mask, root, True, GrabModeAsync, GrabModeAsync); 90 | XGrabKey(dpy, XKeysymToKeycode(dpy, XK_Q), Mod4Mask, root, True, GrabModeAsync, GrabModeAsync); 91 | XGrabKey(dpy, XKeysymToKeycode(dpy, XK_K), Mod4Mask, root, True, GrabModeAsync, GrabModeAsync); 92 | XGrabButton(dpy, AnyButton, Mod4Mask, root, True, ButtonPressMask | ButtonReleaseMask | PointerMotionMask | OwnerGrabButtonMask, 93 | GrabModeAsync, GrabModeAsync, None, None); 94 | 95 | start.subwindow = None; 96 | for (;;) 97 | { 98 | borders(); 99 | XNextEvent(dpy, &ev); 100 | if (ev.type == KeyPress) 101 | { 102 | key = ev.xkey; 103 | if (key.keycode == XKeysymToKeycode(dpy, XK_Return)) 104 | spawn(xterm); 105 | else if (key.keycode == XKeysymToKeycode(dpy, XK_D)) 106 | spawn(dmenu); 107 | else if (key.keycode == XKeysymToKeycode(dpy, XK_Q)) 108 | { 109 | if (ev.xbutton.subwindow != None) 110 | kill_win(ev.xbutton.subwindow); 111 | } 112 | else if (key.keycode == XKeysymToKeycode(dpy, XK_K)) 113 | break; 114 | } 115 | else if (ev.type == ButtonPress && ev.xbutton.subwindow != None) 116 | { 117 | start = ev.xbutton; 118 | XRaiseWindow(dpy, start.subwindow); 119 | XGetWindowAttributes(dpy, start.subwindow, &attr); 120 | } 121 | else if (ev.type == MotionNotify && start.subwindow != None) 122 | { 123 | if (ev.xbutton.y_root < 20) /*U*/ 124 | XMoveResizeWindow(dpy, start.subwindow, 125 | 0, 0, 126 | screen->width, screen->height / 2); 127 | else if (ev.xbutton.y_root > screen->height - 20) /*U*/ 128 | XMoveResizeWindow(dpy, start.subwindow, 129 | 0, screen->height / 2, 130 | screen->width, screen->height / 2); 131 | else if (ev.xbutton.x_root < 20) /*L*/ 132 | XMoveResizeWindow(dpy, start.subwindow, 133 | 0, 0, 134 | screen->width / 2, screen->height); 135 | else if (ev.xbutton.x_root > screen->width - 20) /*R*/ 136 | XMoveResizeWindow(dpy, start.subwindow, 137 | screen->width / 2, 0, 138 | screen->width / 2, screen->height); 139 | else 140 | { 141 | int xdiff = ev.xbutton.x_root - start.x_root; 142 | int ydiff = ev.xbutton.y_root - start.y_root; 143 | XMoveResizeWindow(dpy, start.subwindow, 144 | attr.x + (start.button == 1 ? xdiff : 0), 145 | attr.y + (start.button == 1 ? ydiff : 0), 146 | MAX(1, attr.width + (start.button == 3 ? xdiff : 0)), 147 | MAX(1, attr.height + (start.button == 3 ? ydiff : 0))); 148 | } 149 | } 150 | else if (ev.type == ButtonRelease) 151 | start.subwindow = None; 152 | } 153 | XCloseDisplay(dpy); 154 | return 0; 155 | } --------------------------------------------------------------------------------