From 79843b730b50672311a7191ab69cc305bfab339c Mon Sep 17 00:00:00 2001 From: Abhinav Prasai Date: Mon, 25 Aug 2025 16:18:34 +0100 Subject: add focused checking to prevent crash and make clangd option --- Makefile | 13 ++++++++++--- compile_flags.txt | 8 ++++++++ src/sxwm.c | 8 ++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 compile_flags.txt diff --git a/Makefile b/Makefile index d2a9e59..3faa801 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CC ?= gcc -CFLAGS ?= -std=c99 -Wall -Wextra -O3 -Isrc -LDFLAGS ?= -lX11 -lXinerama -lXcursor +CFLAGS ?= -std=c99 -Wall -Wextra -Os +LDFLAGS ?= -lX11 -lXinerama -lXcursor -Isrc PREFIX ?= /usr/local BIN := sxwm @@ -56,4 +56,11 @@ uninstall: @rm -f $(DESTDIR)$(MAN_DIR)/$(MAN) @echo "Uninstallation complete." -.PHONY: all clean install uninstall +clangd: + @echo "Generating compile_flags.txt" + @rm -f compile_flags.txt + @for flag in $(CFLAGS) $(LDFLAGS); do \ + echo $$flag >> compile_flags.txt; \ + done + +.PHONY: all clean install uninstall clangd diff --git a/compile_flags.txt b/compile_flags.txt new file mode 100644 index 0000000..e568f62 --- /dev/null +++ b/compile_flags.txt @@ -0,0 +1,8 @@ +-std=c99 +-Wall +-Wextra +-Os +-lX11 +-lXinerama +-lXcursor +-Isrc diff --git a/src/sxwm.c b/src/sxwm.c index f7ac401..f1fc94f 100644 --- a/src/sxwm.c +++ b/src/sxwm.c @@ -575,7 +575,9 @@ void focus_next_mon(void) return; } - current_mon = focused->mon; + if (focused) { + current_mon = focused->mon; + } int target_mon = (current_mon + 1) % n_mons; /* find the first window on the target monitor in current workspace */ @@ -614,7 +616,9 @@ void focus_prev_mon(void) return; /* only one monitor, nothing to switch to */ } - current_mon = focused->mon; + if (focused) { + current_mon = focused->mon; + } int target_mon = (current_mon - 1 + n_mons) % n_mons; /* find the first window on the target monitor in current workspace */ -- cgit v1.2.3