summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhinav Prasai <abhinav.prsai@gmail.com>2025-08-25 16:18:34 +0100
committerAbhinav Prasai <abhinav.prsai@gmail.com>2025-08-28 09:54:09 +0100
commit79843b730b50672311a7191ab69cc305bfab339c (patch)
treed11f1474212bb04a28c2199fffceca49ac419a76
parent3e650ef606b6271bab500dd42498e0ad86820e54 (diff)
add focused checking to prevent crash and make clangd option
-rw-r--r--Makefile13
-rw-r--r--compile_flags.txt8
-rw-r--r--src/sxwm.c8
3 files changed, 24 insertions, 5 deletions
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 */