diff options
| -rw-r--r-- | Makefile | 91 | ||||
| -rw-r--r-- | src/sxwm.c | 25 |
2 files changed, 115 insertions, 1 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c283518 --- /dev/null +++ b/Makefile @@ -0,0 +1,91 @@ +# tools +CC ?= cc +PKG_CONFIG ?= pkg-config + +# install dirs +PREFIX ?= /usr/local +DESTDIR ?= +BIN := sxwm +MAN := sxwm.1 +MAN_DIR := $(PREFIX)/share/man/man1 +XSESSIONS := $(DESTDIR)$(PREFIX)/share/xsessions + +# layout +SRC_DIR := src/ +OBJ_DIR := build/ +SRC := $(wildcard $(SRC_DIR)/*.c) +OBJ := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRC)) +DEP := $(OBJ:.o=.d) + +# flags +CPPFLAGS ?= -Isrc -D_FORTIFY_SOURCE=2 + +# compile flags + warnings, hardening +CFLAGS ?= -std=c99 -Os -pipe \ + -Wall -Wextra -Wformat=2 -Werror=format-security \ + -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-strings \ + -Wmissing-prototypes -Wstrict-prototypes -Wswitch-enum \ + -Wundef -Wvla -fno-common -fno-strict-aliasing \ + -fstack-protector-strong -fPIE + +# linker +LDFLAGS ?= -Wl,-O1 -pie + +# libraries +LDLIBS ?= -lX11 -lXinerama -lXcursor + +# prefer pkg-confgi +ifneq ($(shell $(PKG_CONFIG) --exists x11 xinerama xcursor && echo yes),) +CPPFLAGS += $(shell $(PKG_CONFIG) --cflags x11 xinerama xcursor) +LDLIBS := $(shell $(PKG_CONFIG) --libs x11 xinerama xcursor) +endif + +.PHONY: all clean install uninstall clangd +.SUFFIXES: + +all: $(BIN) + +$(BIN): $(OBJ) + $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) + +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR) + @mkdir -p $(dir $@) + $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MP -c -o $@ $< + +-include $(DEP) + +$(OBJ_DIR): + @mkdir -p $@ + +clean: + @rm -rf $(OBJ_DIR) $(BIN) + +install: all + @echo "installing $(BIN) to $(DESTDIR)$(PREFIX)/bin..." + @mkdir -p "$(DESTDIR)$(PREFIX)/bin" + @install -m 755 $(BIN) "$(DESTDIR)$(PREFIX)/bin/$(BIN)" + @echo "installing sxwm.desktop to $(XSESSIONS)..." + @mkdir -p "$(XSESSIONS)" + @install -m 644 sxwm.desktop "$(XSESSIONS)/sxwm.desktop" + @echo "installing man page to $(DESTDIR)$(MAN_DIR)..." + @mkdir -p "$(DESTDIR)$(MAN_DIR)" + @install -m 644 $(MAN) "$(DESTDIR)$(MAN_DIR)/" + @echo "copying default config to $(DESTDIR)$(PREFIX)/share/sxwmrc..." + @mkdir -p "$(DESTDIR)$(PREFIX)/share" + @install -m 644 default_sxwmrc "$(DESTDIR)$(PREFIX)/share/sxwmrc" + @echo "installation complete :)" + +uninstall: + @echo "uninstalling $(BIN) from $(DESTDIR)$(PREFIX)/bin..." + @rm -f "$(DESTDIR)$(PREFIX)/bin/$(BIN)" + @echo "uninstalling sxwm.desktop from $(XSESSIONS)..." + @rm -f "$(XSESSIONS)/sxwm.desktop" + @echo "uninstalling man page from $(DESTDIR)$(MAN_DIR)..." + @rm -f "$(DESTDIR)$(MAN_DIR)/$(MAN)" + @echo "uninstallation complete :)" + +# dev tools +clangd: + @echo "generating compile_flags.txt" + @rm -f compile_flags.txt + @for flag in $(CPPFLAGS) $(CFLAGS); do echo $$flag >> compile_flags.txt; done @@ -99,6 +99,7 @@ void set_frame_extents(Window w); void set_input_focus(Client *c, Bool raise_win, Bool warp); void set_opacity(Window w, double opacity); void set_win_scratchpad(int n); +void set_wm_state(Window w, long state); int snap_coordinate(int pos, int size, int screen_size, int snap_dist); void spawn(const char * const *argv); void startup_exec(void); @@ -127,6 +128,7 @@ Atom _NET_ACTIVE_WINDOW; Atom _NET_CURRENT_DESKTOP; Atom _NET_SUPPORTED; Atom _NET_WM_STATE; +Atom WM_STATE; Atom _NET_WM_WINDOW_TYPE; Atom _NET_WORKAREA; Atom WM_DELETE_WINDOW; @@ -1117,6 +1119,7 @@ void hdl_map_req(XEvent *xev) if (!c) { return; } + set_wm_state(w, NormalState); Window transient; if (!should_float && XGetTransientForHint(dpy, w, &transient)) { @@ -2057,6 +2060,7 @@ void setup_atoms(void) _NET_WM_WINDOW_TYPE = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False); _NET_WORKAREA = XInternAtom(dpy, "_NET_WORKAREA", False); _NET_WM_STATE = XInternAtom(dpy, "_NET_WM_STATE", False); + WM_STATE = XInternAtom(dpy, "WM_STATE", False); WM_DELETE_WINDOW = XInternAtom(dpy, "WM_DELETE_WINDOW", False); _NET_SUPPORTING_WM_CHECK = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False); _NET_WM_NAME = XInternAtom(dpy, "_NET_WM_NAME", False); @@ -2078,7 +2082,6 @@ void setup_atoms(void) _NET_WM_WINDOW_TYPE_NOTIFICATION = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_NOTIFICATION", False); _NET_WM_STATE_MODAL = XInternAtom(dpy, "_NET_WM_STATE_MODAL", False); - Atom support_list[] = { _NET_CURRENT_DESKTOP, _NET_ACTIVE_WINDOW, _NET_SUPPORTED, _NET_WM_STATE, _NET_WM_WINDOW_TYPE, _NET_WORKAREA, _NET_WM_STRUT, @@ -2091,6 +2094,19 @@ void setup_atoms(void) _NET_WM_WINDOW_TYPE_NOTIFICATION, _NET_WM_STATE_MODAL, }; + /* checking window */ + wm_check_win = XCreateSimpleWindow(dpy, root, 0, 0, 1, 1, 0, 0, 0); + /* root property -> child window */ + XChangeProperty(dpy, root, _NET_SUPPORTING_WM_CHECK, XA_WINDOW, 32, + PropModeReplace, (unsigned char *)&wm_check_win, 1); + /* child window -> child window */ + XChangeProperty(dpy, wm_check_win, _NET_SUPPORTING_WM_CHECK, XA_WINDOW, 32, + PropModeReplace, (unsigned char *)&wm_check_win, 1); + /* name the wm */ + const char *wmname = "sxwm"; + XChangeProperty(dpy, wm_check_win, _NET_WM_NAME, UTF8_STRING, 8, + PropModeReplace, (const unsigned char *)wmname, strlen(wmname)); + /* workspace setup */ long num_workspaces = NUM_WORKSPACES; XChangeProperty(dpy, root, _NET_NUMBER_OF_DESKTOPS, XA_CARDINAL, 32, @@ -2197,6 +2213,13 @@ void set_opacity(Window w, double opacity) XChangeProperty(dpy, w, atom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&op, 1); } +void set_wm_state(Window w, long state) +{ + long data[2] = { state, None }; /* state, icon window */ + XChangeProperty(dpy, w, WM_STATE, WM_STATE, 32, + PropModeReplace, (unsigned char *)data, 2); +} + int snap_coordinate(int pos, int size, int screen_size, int snap_dist) { if (UDIST(pos, 0) <= snap_dist) { |
