Skip to content

Instantly share code, notes, and snippets.

@dezren39
Forked from intrntbrn/resize-increment.c
Created July 31, 2024 03:33
Show Gist options
  • Save dezren39/b3fadead7036cf172e9abd6ac953f92f to your computer and use it in GitHub Desktop.
Save dezren39/b3fadead7036cf172e9abd6ac953f92f to your computer and use it in GitHub Desktop.
set WM_NORMAL_HINTS program specified resize increment for any client (e.g. alacritty)
/*
* Author: intrntbrn
*
* Compile with:
* gcc resize-increment.c -Wall -o resize-increment `pkg-config --cflags --libs x11`
*
* Usage:
* resize-increment windowid width_inc height_inc
* e.g.: resize-increment 1234567 6 12
*/
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void SetWmSizeHints(Display *display, Window window, int width_inc,
int height_inc) {
XSizeHints *hints = XAllocSizeHints();
hints->flags = PResizeInc;
hints->width_inc = width_inc;
hints->height_inc = height_inc;
XSetWMSizeHints(display, window, hints, XA_WM_NORMAL_HINTS);
XFree(hints);
}
int main(int argc, char *argv[]) {
Display *display;
Window window;
int width_inc, height_inc;
display = XOpenDisplay(NULL);
if (display == NULL)
return 1;
window = 0;
if (argc > 3) {
sscanf(argv[1], "0x%lx", &window);
if (window == 0)
sscanf(argv[1], "%lu", &window);
sscanf(argv[2], "%u", &width_inc);
sscanf(argv[3], "%u", &height_inc);
}
if (window == 0)
return 1;
SetWmSizeHints(display, window, width_inc, height_inc);
XCloseDisplay(display);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment