Remove xeventbind

Since I don't change resolutions as often if at all anymore, this
isn't needed.
This commit is contained in:
Donovan Glover 2021-05-10 10:07:13 -04:00
parent 3cbbbd1255
commit a8a0055c49
No known key found for this signature in database
GPG Key ID: EA7408A77AE1BE65
11 changed files with 33 additions and 438 deletions

View File

@ -8,4 +8,3 @@ Note that you can install multiple DEs and WMs at once, then switch between them
- [color-scripts](/.archlinux/PKGBUILDs/color-scripts) - Color scripts, purely for aesthetics - [color-scripts](/.archlinux/PKGBUILDs/color-scripts) - Color scripts, purely for aesthetics
- [tari-core](/.archlinux/PKGBUILDs/tari-core) - Meta package for my Arch Linux installation - [tari-core](/.archlinux/PKGBUILDs/tari-core) - Meta package for my Arch Linux installation
- [xeventbind](/.archlinux/PKGBUILDs/xeventbind) - Useful to change X DPI on resolution change

View File

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2016 Olaf Tomalka
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,17 +0,0 @@
CC=gcc
CFLAGS=-O2
LIBS=-lX11
OBJ=main.o xeb_handler.o
.PHONY: all clean
all: xeventbind
xeventbind: $(OBJ)
$(CC) -o $@ $^ $(LIBS) $(CFLAGS)
%.o: %.c
$(CC) -c -o $@ $< $(CLAGS)
clean:
rm -f xeventbind *.o

View File

@ -1,30 +0,0 @@
pkgname=xeventbind
pkgver=0.1.0
pkgrel=1
pkgdesc="Run a script on resolution change"
arch=('any')
license=('MIT')
depends=('libx11')
source=(
'xeb_event_types.h'
'xeb_handler.c'
'xeb_handler.h'
'main.c'
'Makefile'
'LICENSE'
)
sha256sums=('5e55b56bc1fc281d2549bb892a1a7e93f5eb7cb7ff88d3216345907456d02801'
'9a26c895d79244c76e3c9b5842dab6e6d4b628842f6f63a3001d4563c253a28b'
'b57396a210fde7858928c1e44febd1cecc2aa715b58ca11590afddc5aa3d7a75'
'1d44006d8e14ebd062415a8f20d746fe8771eacf5165d3064f20401b9ddca32d'
'420ee5dc1349c226423bf009a71a3f0b0b33456ffdf35d682fc12ee5b4dd207f'
'e219b161877df1f1986c4e79794fde8b6cb209da7bc4b4442b925da0d7fd93ee')
build() {
make
}
package() {
install -Dm 755 xeventbind "$pkgdir"/usr/bin/xeventbind
install -Dm 644 LICENSE "$pkgdir"/usr/share/licenses/xeventbind/LICENSE
}

View File

@ -1,107 +0,0 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 Olaf Tomalka
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include "xeb_event_types.h"
#include "xeb_handler.h"
struct arguments {
xeb_event_type event_type;
char *script_path;
};
struct event_map {
char *str;
xeb_event_type event;
};
static struct event_map mapping[] = {
{"resolution", ResolutionChange}
};
void print_usage(char *path) {
fprintf(stderr, "Usage: %s event_type script_path\n", path);
fprintf(stderr, "Event types:\n");
size_t mapping_size = sizeof(mapping) / sizeof(mapping[0]);
for (int i = 0; i < mapping_size; i++) {
fprintf(stderr, "\t%s\n", mapping[i].str);
}
exit(EXIT_FAILURE);
}
void parse_args(int argc, char** argv, struct arguments *args) {
if (argc != 3)
print_usage(argv[0]);
size_t mapping_size = sizeof(mapping) / sizeof(mapping[0]);
int found = 0;
for (int i = 0; i < mapping_size; i++) {
if (strcmp(argv[1], mapping[i].str) == 0) {
found = 1;
args->event_type = mapping[i].event;
break;
}
}
if (!found)
print_usage(argv[0]);
args->script_path = argv[2];
}
int handle_callback(xeb_event_type event, void *data) {
assert(data);
struct arguments *args = data;
assert(args->event_type == event);
pid_t pid = fork();
int err;
switch (pid) {
case -1:
perror("Failed to fork\n");
exit(EXIT_FAILURE);
break;
case 0: // Child
err = execlp(args->script_path, NULL);
if (err == -1) {
perror("Failed to open callback script\n");
exit(EXIT_FAILURE);
}
break;
}
}
int main(int argc, char **argv) {
struct arguments args;
int err;
parse_args(argc, argv, &args);
xeb_add_callback(args.event_type, handle_callback, &args);
return xeb_loop() ? EXIT_FAILURE : EXIT_SUCCESS;
}

View File

@ -1,31 +0,0 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 Olaf Tomalka
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef _XEVENTBIND_EVENT_TYPES_H
#define _XEVENTBIND_EVENT_TYPES_H
typedef enum {
ResolutionChange
} xeb_event_type;
#endif

View File

@ -1,131 +0,0 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 Olaf Tomalka
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <assert.h>
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "xeb_handler.h"
struct callback_data {
xeb_callback func;
void *data;
xeb_event_type event;
};
struct dimensions {
int width, height;
};
static struct callback_data *callbacks = NULL;
static int callbacks_count = 0;
static int callbacks_capacity = 0;
static void ensure_enough_callback_space(void) {
if (callbacks_count == 0)
return;
if (callbacks_capacity == 0) {
callbacks = malloc(callbacks_count * sizeof(struct callback_data));
callbacks_capacity = callbacks_count;
} else if (callbacks_count > callbacks_capacity) {
int new_size = callbacks_capacity;
while (new_size < callbacks_count)
new_size *= 2;
callbacks_capacity = new_size;
struct callback_dat *new_call = realloc(
callbacks,
callbacks_capacity * sizeof(struct callback_data));
if (new_call == NULL) {
fprintf(stderr, "Failed to realloc callback_data array\n");
exit(EXIT_FAILURE);
}
}
}
void xeb_add_callback(xeb_event_type event, xeb_callback func, void* data) {
assert(func != NULL);
callbacks_count++;
ensure_enough_callback_space();
struct callback_data *row = &callbacks[callbacks_count - 1];
row->event = event;
row->func = func;
row->data = data;
}
static void call_callbacks(xeb_event_type event) {
for (int i = 0; i < callbacks_count; i++) {
struct callback_data callback = callbacks[i];
if (callback.event == event) {
callback.func(event, callback.data);
}
}
}
int xeb_loop(void) {
Display *display = XOpenDisplay(NULL);
if (!display) {
fprintf(stderr, "Failed to open display\n");
return -1;
}
int screen_count = ScreenCount(display);
Window roots[screen_count];
struct dimensions dimens[screen_count];
for (int i = 0; i < screen_count; i++) {
roots[i] = RootWindow(display, i);
XWindowAttributes attrs;
Status status = XGetWindowAttributes(display, roots[i], &attrs);
if (!status) {
fprintf(stderr, "Failed to get root window attributes for screen: %d\n", i);
return -1;
}
dimens[i].width = attrs.width;
dimens[i].height = attrs.height;
XSelectInput(display, roots[i], StructureNotifyMask);
}
for (;;) {
XEvent e;
XNextEvent(display, &e);
if (e.type == ConfigureNotify) {
XConfigureEvent xce = e.xconfigure;
for (int i = 0; i < screen_count; i++) {
if (xce.window == roots[i]) {
if (xce.width != dimens[i].width || xce.height != dimens[i].height) {
dimens[i].width = xce.width;
dimens[i].height = xce.height;
call_callbacks(ResolutionChange);
}
break;
}
}
}
}
}

View File

@ -1,44 +0,0 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 Olaf Tomalka
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef _XEVENTBIND_HANDLER_H
#define _XEVENTBIND_HANDLER_H
#include "xeb_event_types.h"
typedef int xeb_callback_id;
/**
* @param event An event that this function was called for
* @param data A pointer to, optional, user defined input for the callback function
* @return 0 on success, anything else for error */
typedef int(*xeb_callback)(xeb_event_type event, void* data);
/**
* \brief Starts the event loop and blocks the thread until xeb_stop is called
* @return 0 on sucess, -1 on error
*/
int xeb_loop(void);
void xeb_add_callback(xeb_event_type event, xeb_callback func, void* data);
#endif

View File

@ -49,12 +49,42 @@ xset s off -dpms
compton -b compton -b
# Start polybar and other things based on DPI # Start polybar and other things based on DPI
~/.config/xeventbind/on-resolution-change.sh # Get the host width
HOST_WIDTH=$(bspc query -T -m | jq '.rectangle.width')
if hash xeventbind 2>/dev/null; then CURSOR_THEME=${XCURSOR_THEME:-breeze_cursors}
xeventbind resolution $HOME/.config/xeventbind/on-resolution-change.sh &
# If the DPI is not set, set it to 96 by default
if [ -z "$(xrdb -query | grep dpi)" ]; then
X_DPI=96
fi fi
# Determine the DPI based on screen width
if [ "$HOST_WIDTH" -eq "1920" ]; then
X_DPI=96
fi
if [ "$HOST_WIDTH" -eq "3840" ]; then
X_DPI=192
fi
# Reposition the desktop background
~/.fehbg &
# If the DPI needs to be changed, change it
if [ "$X_DPI" ]; then
echo "Xft.dpi:$X_DPI" | xrdb -merge
# Change the X cursor size as well
# NOTE: For full effect, this needs to be used in combination with XCURSOR_SIZE.
# NOTE: ($X_DPI / 6) here means that 4k will use cursor size 32, so it will appear
# about half the size of the 1080p cursor. If this is not what you want, use
# cursor size 64 instead.
xsetroot -xcf "/usr/share/icons/$CURSOR_THEME/cursors/left_ptr" "$(($X_DPI / 6))"
fi
~/.config/polybar/launch.sh main &
# bspc rules # bspc rules
bspc rule -a mpv state=floating bspc rule -a mpv state=floating
bspc rule -a feh state=floating bspc rule -a feh state=floating

View File

@ -1,38 +0,0 @@
#!/bin/sh
# Get the host width
HOST_WIDTH=$(bspc query -T -m | jq '.rectangle.width')
CURSOR_THEME=${XCURSOR_THEME:-breeze_cursors}
# If the DPI is not set, set it to 96 by default
if [ -z "$(xrdb -query | grep dpi)" ]; then
X_DPI=96
fi
# Determine the DPI based on screen width
if [ "$HOST_WIDTH" -eq "1920" ]; then
X_DPI=96
fi
if [ "$HOST_WIDTH" -eq "3840" ]; then
X_DPI=192
fi
# Reposition the desktop background
~/.fehbg &
# If the DPI needs to be changed, change it
if [ "$X_DPI" ]; then
echo "Xft.dpi:$X_DPI" | xrdb -merge
# Change the X cursor size as well
# NOTE: For full effect, this needs to be used in combination with XCURSOR_SIZE.
# NOTE: ($X_DPI / 6) here means that 4k will use cursor size 32, so it will appear
# about half the size of the 1080p cursor. If this is not what you want, use
# cursor size 64 instead.
xsetroot -xcf "/usr/share/icons/$CURSOR_THEME/cursors/left_ptr" "$(($X_DPI / 6))"
fi
# Reload polybar with the new width / DPI
~/.config/polybar/launch.sh main &

View File

@ -1,15 +0,0 @@
# xeventbind
[xeventbind][xeventbind] is used to run a script on resolution change.
## Use Cases
xeventbind can be used to:
- Change the X DPI for specific resolutions, useful, for example, if you switch between traditional and HiDPI displays often
You should not use xeventbind if:
- You don't change resolutions often or don't need to run anything on resolution change
[xeventbind]: https://github.com/ritave/xeventbind