Skip to content

Instantly share code, notes, and snippets.

@intrntbrn
Created May 21, 2021 18:14
Show Gist options
  • Save intrntbrn/99bccdc6b06b47b8b44c12908b13b6ac to your computer and use it in GitHub Desktop.
Save intrntbrn/99bccdc6b06b47b8b44c12908b13b6ac 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;
}
@intrntbrn
Copy link
Author

intrntbrn commented May 21, 2021

Shellscript to autospawn resize-increment for a specific process ( alacritty in this example):

#!/bin/bash
alacritty & pid=$!
i=0
while
	windowid=$(xdotool search --pid $pid)
	:
	i="$((i+1))"
	[ -z "$windowid" ] && [ "$i" -lt 100 ]
do :;  done
[ -z "$windowid" ] && exit 1
resize-increment "$windowid" 6 12

You may need to adjust the limit of$i (100).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment