Fix config parsing and OSD dragging issues
Config parsing: - Add strip_inline_comment() helper to remove // comments from values - Fixes "No such key name '//'" and "No such key name 'Set'" errors - Function values like "bracketright // comment" now parse correctly OSD dragging: - Add ButtonMotionMask for more reliable drag event detection - Add XFlush after XMoveWindow for immediate visual feedback - Coalesce pending motion events to prevent lag during fast drags https://claude.ai/code/session_01H5sr8TkRyt6U1vdkVZRRvy
+28 −1 · 2 files changed
-
src/config.c+23 −0 -
src/osd.c+5 −1
@@ -26,6 +26,25 @@ static wheel_mode_t parse_wheel_mode(const char* mode_str) { return WHEEL_MODE_SEQUENTIAL; } +// Helper function to strip inline comments (// ...) and trailing whitespace +static char* strip_inline_comment(char* str) { + if (str == NULL) return NULL; + + // Find // and terminate string there + char* comment = strstr(str, "//"); + if (comment != NULL) { + *comment = '\0'; + } + + // Strip trailing whitespace + size_t len = strlen(str); + while (len > 0 && (str[len-1] == ' ' || str[len-1] == '\t' || str[len-1] == '\n' || str[len-1] == '\r')) { + str[--len] = '\0'; + } + + return str; +} + // Create a new configuration structure config_t* config_create(void) { config_t* config = malloc(sizeof(config_t)); @@ -424,7 +443,11 @@ int config_load(config_t* config, const char* filename, int debug) { char* func_str = line + 9; while (*func_str == ' ') func_str++; + // Strip inline comments and trailing whitespace char* func_copy = strdup(func_str); + if (func_copy != NULL) { + strip_inline_comment(func_copy); + } if (func_copy == NULL) { printf("Memory allocation failed!\n"); fclose(f); @@ -156,7 +156,7 @@ int osd_init_display(osd_state_t* osd) { attrs.background_pixel = 0; // Transparent background attrs.border_pixel = 0; attrs.event_mask = ExposureMask | ButtonPressMask | ButtonReleaseMask | - PointerMotionMask | StructureNotifyMask; + PointerMotionMask | ButtonMotionMask | StructureNotifyMask; // Create the window Window win = XCreateWindow(dpy, RootWindow(dpy, osd->screen), @@ -549,9 +549,13 @@ void osd_update(osd_state_t* osd) { case MotionNotify: if (osd->dragging) { + // Consume all pending motion events (coalesce) + while (XCheckTypedWindowEvent(dpy, win, MotionNotify, &event)); + osd->pos_x = event.xmotion.x_root - osd->drag_start_x; osd->pos_y = event.xmotion.y_root - osd->drag_start_y; XMoveWindow(dpy, win, osd->pos_x, osd->pos_y); + XFlush(dpy); } break;