From e8f2785196c08153ccdbe0a147b62ff06158aae4 Mon Sep 17 00:00:00 2001 From: xezo360hye Date: Sun, 16 Oct 2022 16:10:48 +0300 Subject: [PATCH 1/6] Code refactoring without functionality changes Internal functions start with _underscore now, added -- after xdotool commands, replaced infinite loop in nowm_main with sleep infinity This commit is mostly to prepare for bigger changes and might be skipped by now --- bin/nowm | 143 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 88 insertions(+), 55 deletions(-) diff --git a/bin/nowm b/bin/nowm index ad180c6..97ac9ab 100755 --- a/bin/nowm +++ b/bin/nowm @@ -1,74 +1,107 @@ #!/bin/sh -resize() { xdotool getwindowfocus windowsize "${1:-0}" "${2:-0}"; } - -resize_relative() { - eval "$(xdotool getwindowfocus getwindowgeometry --shell | head -n5)" - W_WIDTH=$(( WIDTH + "${1:-0}" )); W_HEIGHT=$(( HEIGHT + "${2:-0}" )) - eval "$(xdotool getdisplaygeometry --shell)" - DR_WIDTH="$(( WIDTH - X ))"; DR_HEIGHT="$(( HEIGHT - Y ))" - [ "${W_WIDTH}" -lt 1 ] && W_WIDTH=1 || [ "${W_WIDTH}" -gt "${DR_WIDTH}" ] && W_WIDTH="${DR_WIDTH}" - [ "${W_HEIGHT}" -lt 1 ] && W_HEIGHT=1 || [ "${W_HEIGHT}" -gt "${DR_HEIGHT}" ] && W_HEIGHT="${DR_HEIGHT}" - xdotool windowsize "${WINDOW}" "${W_WIDTH}" "${W_HEIGHT}" +_resize() { + xdotool getwindowfocus windowsize -- "${1:-0}" "${2:-0}" } -move() { xdotool getwindowfocus windowmove "${1:-0}" "${2:-0}"; } +_resize_relative() { + eval "$(xdotool getwindowfocus getwindowgeometry --shell | awk "/WIDTH|HEIGHT/")" + WINDOW_WIDTH=$(( WIDTH + "${1:-0}" )) + WINDOW_HEIGHT=$(( HEIGHT + "${2:-0}" )) -move_relative() { xdotool getwindowfocus windowmove --relative "${1:-0}" "${2:-0}"; } + eval "$(xdotool getdisplaygeometry --shell | awk "/WIDTH|HEIGHT|X|Y/")" + DISPLAY_WIDTH="$(( WIDTH - X ))" + DISPLAY_HEIGHT="$(( HEIGHT - Y ))" -center() { - eval "$(xdotool getwindowfocus getwindowgeometry --shell | tail -n3 | head -n2)" - W_WIDTH="${WIDTH}"; W_HEIGHT="${HEIGHT}" - eval "$(xdotool getdisplaygeometry --shell)" - move "$(( (WIDTH - W_WIDTH) / 2 ))" "$(( (HEIGHT - W_HEIGHT) / 2 ))" + if [[ "${WINDOW_WIDTH}" < 1 ]]; then + WINDOW_WIDTH=1 + elif [[ "${WINDOW_WIDTH}" > "${DISPLAY_WIDTH}" ]]; then + WINDOW_WIDTH="${DISPLAY_WIDTH}" + fi + + if [[ "${WINDOW_HEIGHT}" < 1 ]]; then + WINDOW_HEIGHT=1 + elif [[ "${WINDOW_HEIGHT}" > "${DISPLAY_HEIGHT}" ]]; then + WINDOW_HEIGHT="${DISPLAY_HEIGHT}" + fi + + xdotool windowsize -- "${WINDOW}" "${WINDOW_WIDTH}" "${WINDOW_HEIGHT}" +} + +_move() { + xdotool getwindowfocus windowmove -- "${1:-0}" "${2:-0}" +} + +_move_relative() { + xdotool getwindowfocus windowmove --relative -- "${1:-0}" "${2:-0}" +} + +_center() { + eval "$(xdotool getwindowfocus getwindowgeometry --shell | tail -n3 | head -n2)" + WINDOW_WIDTH="${WIDTH}" + WINDOW_HEIGHT="${HEIGHT}" + eval "$(xdotool getdisplaygeometry --shell | awk "/WIDTH|HEIGHT/")" + move "$(( (WIDTH - WINDOW_WIDTH) / 2 ))" "$(( (HEIGHT - WINDOW_HEIGHT) / 2 ))" } -snap() { - eval "$(xdotool getwindowfocus getwindowgeometry --shell | head -n5)" - W_WIDTH="${WIDTH}"; W_HEIGHT="${HEIGHT}" - eval "$(xdotool getdisplaygeometry --shell)" - case "${1:-0}" in - left) move 0 y ;; - bottom) move x "$(( HEIGHT - W_HEIGHT ))";; - top) move x 0 ;; - right) move "$(( WIDTH - W_WIDTH ))" y ;; - *) move x y ;; - esac +_snap() { + eval "$(xdotool getwindowfocus getwindowgeometry --shell | awk "/WIDTH|HEIGHT/")" + W_WIDTH="${WIDTH}" + W_HEIGHT="${HEIGHT}" + eval "$(xdotool getdisplaygeometry --shell)" + case "${1:-0}" in + left) move 0 y ;; + bottom) move x "$(( HEIGHT - W_HEIGHT ))";; + top) move x 0 ;; + right) move "$(( WIDTH - W_WIDTH ))" y ;; + *) move x y ;; + esac } -pointer_focus() { xdotool getmouselocation windowfocus; } +_pointer_focus() { + xdotool getmouselocation windowfocus +} -select_focus() { xdotool selectwindow windowfocus; } +_select_focus() { + xdotool selectwindow windowfocus +} -close() { xdotool getwindowfocus windowclose; } +_close() { + xdotool getwindowfocus windowclose +} -quit() { xdotool getwindowfocus windowquit; } +_quit() { + xdotool getwindowfocus windowquit +} -window_kill() { xdotool getwindowfocus windowkill; } +_kill() { + xdotool getwindowfocus windowkill +} -nowm_logout() { pkill -KILL -u "$(whoami)"; } +_logout() { + pkill -KILL -u "$(whoami)" +} nowm_main() { - NOWM_AUTOSTART="${XDG_CONFIG_HOME:-${HOME}/.config}/nowm/autostart" - [ -x "${NOWM_AUTOSTART}" ] && "${NOWM_AUTOSTART}" >/dev/null 2>&1 & - while : ; do : ; done + NOWM_AUTOSTART="${XDG_CONFIG_HOME:-${HOME}/.config}/nowm/autostart" + [ -x "${NOWM_AUTOSTART}" ] && "${NOWM_AUTOSTART}" >/dev/null 2>&1 & + sleep infinity +} + +noargs() { + if [ -z "${DISPLAY}" ]; then + exec startx "$(which nowm)" + else + nowm_main + fi } -noargs() { if [ -z "${DISPLAY}" ]; then exec startx "$(which nowm)"; else nowm_main; fi; } - -case "${1}" in - "") noargs || exit 1 ;; - resize) resize "${2}" "${3}";; - resize_relative) resize_relative "${2}" "${3}";; - move) move "${2}" "${3}";; - move_relative) move_relative "${2}" "${3}";; - center) center ;; - snap) snap "${2}" ;; - pointer_focus) pointer_focus ;; - select_focus) select_focus ;; - close) close ;; - quit) quit ;; - kill) window_kill ;; - logout) nowm_logout ;; - *) exit 1 ;; -esac +valid="resize|resize_relative|move|move_relative|center|snap|pointer_focus|select_focus|close|quit|kill|logout" +if [[ "$1" =~ ^(${valid})$ ]]; then + _"$1" "${@:2}" +elif [[ -z "$1" ]]; then + noargs +else + echo "Invalid command: $1" + exit 1 +fi From 1d33842f90c8cbb3f159056a48e8aee832b1ecc1 Mon Sep 17 00:00:00 2001 From: xezo360hye Date: Mon, 17 Oct 2022 08:30:50 +0300 Subject: [PATCH 2/6] Changes in files structure and code reformatting Now all files that can/should be installed are placed in src/ directory. Added nowm.desktop file. Made some changes to main executable This commit should NOW be merged right now --- Makefile | 24 ++++++++++++++++-------- README.md | 4 ++-- {bin => src}/nowm | 16 +++++++++------- {man => src}/nowm.1 | 0 src/nowm.desktop | 6 ++++++ 5 files changed, 33 insertions(+), 17 deletions(-) rename {bin => src}/nowm (90%) rename {man => src}/nowm.1 (100%) create mode 100644 src/nowm.desktop diff --git a/Makefile b/Makefile index 30fa935..dd5b4dd 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,25 @@ -PREFIX ?= /usr/local -MANDIR ?= $(PREFIX)/share/man -BIN ?= nowm +PREFIX ?= /usr/local +DESKTOP ?= /usr/share/xsessions +MANDIR ?= $(PREFIX)/share/man +BIN ?= nowm install: + @echo "Installing $(BIN) to $(PREFIX)/bin" @mkdir -p $(PREFIX)/bin - @mkdir -p $(MANDIR)/man1 - - @cp -p bin/$(BIN) $(PREFIX)/bin/ - @cp -p man/$(BIN).1 $(MANDIR)/man1/ - + @cp -p src/$(BIN) $(PREFIX)/bin/ @chmod 755 $(PREFIX)/bin/$(BIN) + + @echo "Installing $(BIN).1 to $(MANDIR)/man1" + @mkdir -p $(MANDIR)/man1 + @cp -p src/$(BIN).1 $(MANDIR)/man1/ + + @echo "Installing $(BIN).desktop to $(DESKTOP)" + @mkdir -p $(DESKTOP) + @cp -p src/$(BIN).desktop $(DESKTOP)/ uninstall: @rm -rf $(PREFIX)/bin/$(BIN) @rm -rf $(MANDIR)/man1/$(BIN).1* + @rm -rf $(DESKTOP)/$(BIN).desktop + @echo "Uninstalled $(BIN)" diff --git a/README.md b/README.md index 0177263..8bde003 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ A dead simple tool to managing windows from the [tty](https://en.wikipedia.org/w Option 1: using `curl` ```sh -curl https://raw.githubusercontent.com/K4zoku/nowm/master/bin/nowm > ~/.local/bin/nowm +curl https://raw.githubusercontent.com/K4zoku/nowm/master/src/nowm > ~/.local/bin/nowm chmod +x ~/.local/bin/nowm ``` @@ -45,7 +45,7 @@ Option 2: using `git` ```sh git clone https://github.com/K4zoku/nowm.git ~/.local/share/nowm -ln -s ~/.local/share/nowm/bin/nowm ~/.local/bin/nowm +ln -s ~/.local/share/nowm/src/nowm ~/.local/bin/nowm ``` #### 📦 Package manager diff --git a/bin/nowm b/src/nowm similarity index 90% rename from bin/nowm rename to src/nowm index 97ac9ab..90a966d 100755 --- a/bin/nowm +++ b/src/nowm @@ -60,6 +60,10 @@ _snap() { _pointer_focus() { xdotool getmouselocation windowfocus + + if [[ "$NOWM_RAISE_FOCUS" ]]; then + xdotool getwindowfocus windowraise + fi } _select_focus() { @@ -82,17 +86,15 @@ _logout() { pkill -KILL -u "$(whoami)" } -nowm_main() { - NOWM_AUTOSTART="${XDG_CONFIG_HOME:-${HOME}/.config}/nowm/autostart" - [ -x "${NOWM_AUTOSTART}" ] && "${NOWM_AUTOSTART}" >/dev/null 2>&1 & - sleep infinity -} - noargs() { if [ -z "${DISPLAY}" ]; then + NOWM_AUTOSTART="${XDG_CONFIG_HOME:-${HOME}/.config}/nowm/autostart" + if [[ -f "${NOWM_AUTOSTART}" ]]; then + source "${NOWM_AUTOSTART}" + fi exec startx "$(which nowm)" else - nowm_main + sleep infinity fi } diff --git a/man/nowm.1 b/src/nowm.1 similarity index 100% rename from man/nowm.1 rename to src/nowm.1 diff --git a/src/nowm.desktop b/src/nowm.desktop new file mode 100644 index 0000000..6008aa7 --- /dev/null +++ b/src/nowm.desktop @@ -0,0 +1,6 @@ +[Desktop Entry] +Name=NoWM (X11) +Comment=NoWM - managing window without a window manager +Exec=nowm +TryExec=nowm +Type=XSession From abf151ac6257f952b592b6969841d9800008cbaf Mon Sep 17 00:00:00 2001 From: xezo360hye Date: Thu, 20 Oct 2022 21:06:00 +0300 Subject: [PATCH 3/6] Returned to POSIX sh and simplified some things --- src/nowm | 64 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/src/nowm b/src/nowm index 90a966d..8f2104e 100755 --- a/src/nowm +++ b/src/nowm @@ -5,23 +5,23 @@ _resize() { } _resize_relative() { - eval "$(xdotool getwindowfocus getwindowgeometry --shell | awk "/WIDTH|HEIGHT/")" + eval "$(xdotool getwindowfocus getwindowgeometry --shell)" WINDOW_WIDTH=$(( WIDTH + "${1:-0}" )) WINDOW_HEIGHT=$(( HEIGHT + "${2:-0}" )) - eval "$(xdotool getdisplaygeometry --shell | awk "/WIDTH|HEIGHT|X|Y/")" + eval "$(xdotool getdisplaygeometry --shell)" DISPLAY_WIDTH="$(( WIDTH - X ))" DISPLAY_HEIGHT="$(( HEIGHT - Y ))" - if [[ "${WINDOW_WIDTH}" < 1 ]]; then + if [ "${WINDOW_WIDTH}" -lt 1 ]; then WINDOW_WIDTH=1 - elif [[ "${WINDOW_WIDTH}" > "${DISPLAY_WIDTH}" ]]; then + elif [ "${WINDOW_WIDTH}" -gt "${DISPLAY_WIDTH}" ]; then WINDOW_WIDTH="${DISPLAY_WIDTH}" fi - if [[ "${WINDOW_HEIGHT}" < 1 ]]; then + if [ "${WINDOW_HEIGHT}" -lt 1 ]; then WINDOW_HEIGHT=1 - elif [[ "${WINDOW_HEIGHT}" > "${DISPLAY_HEIGHT}" ]]; then + elif [ "${WINDOW_HEIGHT}" -gt "${DISPLAY_HEIGHT}" ]; then WINDOW_HEIGHT="${DISPLAY_HEIGHT}" fi @@ -37,31 +37,31 @@ _move_relative() { } _center() { - eval "$(xdotool getwindowfocus getwindowgeometry --shell | tail -n3 | head -n2)" + eval "$(xdotool getwindowfocus getwindowgeometry --shell)" WINDOW_WIDTH="${WIDTH}" WINDOW_HEIGHT="${HEIGHT}" - eval "$(xdotool getdisplaygeometry --shell | awk "/WIDTH|HEIGHT/")" - move "$(( (WIDTH - WINDOW_WIDTH) / 2 ))" "$(( (HEIGHT - WINDOW_HEIGHT) / 2 ))" + eval "$(xdotool getdisplaygeometry --shell)" + nowm move "$(( (WIDTH - WINDOW_WIDTH) / 2 ))" "$(( (HEIGHT - WINDOW_HEIGHT) / 2 ))" } _snap() { - eval "$(xdotool getwindowfocus getwindowgeometry --shell | awk "/WIDTH|HEIGHT/")" - W_WIDTH="${WIDTH}" - W_HEIGHT="${HEIGHT}" + eval "$(xdotool getwindowfocus getwindowgeometry --shell)" + WINDOW_WIDTH="${WIDTH}" + WINDOW_HEIGHT="${HEIGHT}" eval "$(xdotool getdisplaygeometry --shell)" case "${1:-0}" in - left) move 0 y ;; - bottom) move x "$(( HEIGHT - W_HEIGHT ))";; - top) move x 0 ;; - right) move "$(( WIDTH - W_WIDTH ))" y ;; - *) move x y ;; + left) nowm move 0 y ;; + bottom) nowm move x "$(( HEIGHT - WINDOW_HEIGHT ))";; + top) nowm move x 0 ;; + right) nowm move "$(( WIDTH - WINDOW_WIDTH ))" y ;; + *) nowm move x y ;; esac } _pointer_focus() { xdotool getmouselocation windowfocus - if [[ "$NOWM_RAISE_FOCUS" ]]; then + if [ "${NOWM_RAISE_ON_FOCUS}" = "1" ]; then xdotool getwindowfocus windowraise fi } @@ -83,27 +83,35 @@ _kill() { } _logout() { - pkill -KILL -u "$(whoami)" + kill "$NOWM_PID" } +_help() { + cat << EOF +Usage: nowm [ACTION] + +If no action is specified, then, if no graphical server is running, start one and NoWM, otherwise rerun autostart script and sleep +EOF +} + +# Fuck this shit. Seriously. I spent hours trying to figure out why the fuck my postlaunch file doesnt execute just to understand that I'm using startx /usr/bin/nowm instead of the dev version. I'm out. noargs() { if [ -z "${DISPLAY}" ]; then - NOWM_AUTOSTART="${XDG_CONFIG_HOME:-${HOME}/.config}/nowm/autostart" - if [[ -f "${NOWM_AUTOSTART}" ]]; then - source "${NOWM_AUTOSTART}" - fi exec startx "$(which nowm)" else + export NOWM_PID="$$" + NOWM_AUTOSTART="${XDG_CONFIG_HOME:-${HOME}/.config}/nowm/autostart" + [ -x "${NOWM_AUTOSTART}" ] && "${NOWM_AUTOSTART}" sleep infinity fi } -valid="resize|resize_relative|move|move_relative|center|snap|pointer_focus|select_focus|close|quit|kill|logout" -if [[ "$1" =~ ^(${valid})$ ]]; then - _"$1" "${@:2}" -elif [[ -z "$1" ]]; then +valid="resize resize_relative move move_relative center snap pointer_focus select_focus close quit kill logout help" +if echo "${valid}" | grep -wq "${1}" ; then + _"${1}" "${@:2}" +elif [ -z "${1}" ]; then noargs else - echo "Invalid command: $1" + echo "Invalid command: '${1}'" exit 1 fi From 3aca0d14fc1d4b729f01b9427865002607d37275 Mon Sep 17 00:00:00 2001 From: xezo360hye Date: Mon, 24 Oct 2022 08:42:39 +0300 Subject: [PATCH 4/6] Improved NoWM executable and moved files Moved files in examples/ to examples/hotkeys/ to differentiate from other example files which will be added soon. NoWM functions move and resize renamed to move_absolute and resize_absolute accordingly, now functions move and resize detect what you want based on arguments you pass. Using + or - before numbers makes it relative, otherwise absolute --- examples/autostart | 3 - examples/hotkeys/autostart | 5 ++ examples/{ => hotkeys}/sxhkdrc | 18 ++--- package.json | 4 +- src/nowm | 137 +++++++++++++++++++++++++-------- 5 files changed, 123 insertions(+), 44 deletions(-) delete mode 100644 examples/autostart create mode 100644 examples/hotkeys/autostart rename examples/{ => hotkeys}/sxhkdrc (62%) diff --git a/examples/autostart b/examples/autostart deleted file mode 100644 index 8d8b7b4..0000000 --- a/examples/autostart +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -pgrep -x sxhkd || sxkhd -c "${NOWM_CONFIG_HOME}/sxhkdrc" & diff --git a/examples/hotkeys/autostart b/examples/hotkeys/autostart new file mode 100644 index 0000000..4c2b293 --- /dev/null +++ b/examples/hotkeys/autostart @@ -0,0 +1,5 @@ +#!/bin/sh + +# Stop running SXHKD and start new instance +pkill -x sxhkd +sxhkd -c "${NOWM_CONFIG_HOME}/sxhkdrc" & diff --git a/examples/sxhkdrc b/examples/hotkeys/sxhkdrc similarity index 62% rename from examples/sxhkdrc rename to examples/hotkeys/sxhkdrc index 30285bb..e8fdf71 100644 --- a/examples/sxhkdrc +++ b/examples/hotkeys/sxhkdrc @@ -4,11 +4,11 @@ # terminal super + Return - urxvt + urxvt # reload sxhkd configuration files super + Escape - pkill -USR1 -x sxhkd + pkill -USR1 -x sxhkd ################ # NOWM HOTKEYS # @@ -16,20 +16,20 @@ super + Escape # [nowm] logout super + alt + q - nowm logout + nowm logout # [nowm] move super + {Left,Down,Up,Right} - nowm move_relative {-4 0, 0 4, 0 -4, 4 0} + nowm move_relative {-10 0, 0 10, 0 -10, 10 0} # [nowm] resize -super + {a,s,w,d} - nowm resize_relative {-4 0, 0 4, 0 -4, 4 0} +super + {h,j,k,l} + nowm resize_relative {-10 0, 0 10, 0 -10, 10 0} # [nowm] window close -super + w - nowm close +alt + q + nowm close # [nowm] focus ~button1 - nowm pointer_focus + nowm pointer_focus diff --git a/package.json b/package.json index 507a4d1..f369b46 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.0.1", "description": "Managing window without a window manager", "global": "true", - "scripts": ["bin/nowm"], - "files": ["man/nowm.1"], + "scripts": ["src/nowm"], + "files": ["src/nowm.1", "src/nowm.desktop"], "install": "make install" } diff --git a/src/nowm b/src/nowm index 8f2104e..5d95868 100755 --- a/src/nowm +++ b/src/nowm @@ -1,10 +1,16 @@ #!/bin/sh -_resize() { +################# +# Resize window # +################# + +# By absolute size. +nowm_resize_absolute() { xdotool getwindowfocus windowsize -- "${1:-0}" "${2:-0}" } -_resize_relative() { +# By relative size from current size (+/-). +nowm_resize_relative() { eval "$(xdotool getwindowfocus getwindowgeometry --shell)" WINDOW_WIDTH=$(( WIDTH + "${1:-0}" )) WINDOW_HEIGHT=$(( HEIGHT + "${2:-0}" )) @@ -28,15 +34,52 @@ _resize_relative() { xdotool windowsize -- "${WINDOW}" "${WINDOW_WIDTH}" "${WINDOW_HEIGHT}" } -_move() { +# Autodetect. +nowm_resize() { + if echo "${1}" | grep -qE '^(\+|-)[0-9]+$'; then + nowm resize_relative "${1:-0}" 0 + else + nowm resize_absolute "${1:-x}" y + fi + + if echo "${2}" | grep -qE '^(\+|-)[0-9]+$'; then + nowm resize_relative 0 "${2:-0}" + else + nowm resize_absolute x "${2:-y}" + fi +} + +############### +# Move window # +############### + +# By absolute coordinates. +nowm_move_absolute() { xdotool getwindowfocus windowmove -- "${1:-0}" "${2:-0}" } -_move_relative() { +# By relative coordinates from current position. +nowm_move_relative() { xdotool getwindowfocus windowmove --relative -- "${1:-0}" "${2:-0}" } -_center() { +# Autodetect. +nowm_move() { + if echo "${1}" | grep -qE '^(\+|-)[0-9]+$'; then + nowm move_relative "${1:-0}" 0 + else + nowm move_absolute "${1:-x}" y + fi + + if echo "${2}" | grep -qE '^(\+|-)[0-9]+$'; then + nowm move_relative 0 "${2:-0}" + else + nowm move_absolute x "${2:-y}" + fi +} + +# Place at the center of the screen. +nowm_center() { eval "$(xdotool getwindowfocus getwindowgeometry --shell)" WINDOW_WIDTH="${WIDTH}" WINDOW_HEIGHT="${HEIGHT}" @@ -44,7 +87,8 @@ _center() { nowm move "$(( (WIDTH - WINDOW_WIDTH) / 2 ))" "$(( (HEIGHT - WINDOW_HEIGHT) / 2 ))" } -_snap() { +# Place at the side of the screen (left, right, top, bottom). Includes resizing. +nowm_snap() { eval "$(xdotool getwindowfocus getwindowgeometry --shell)" WINDOW_WIDTH="${WIDTH}" WINDOW_HEIGHT="${HEIGHT}" @@ -58,44 +102,55 @@ _snap() { esac } -_pointer_focus() { + +############################## +# Manipulations with windows # +############################## + +# Focus window under cursor. +nowm_pointer_focus() { xdotool getmouselocation windowfocus +} - if [ "${NOWM_RAISE_ON_FOCUS}" = "1" ]; then - xdotool getwindowfocus windowraise - fi +# Raise focused window. Useful in combination 'nowm pointer_focus && nowm raise'. +nowm_raise() { + xdotool getwindowfocus windowraise } -_select_focus() { +#TODO +# Select window by clicking on it. Useless imo. +nowm_select_focus() { xdotool selectwindow windowfocus } -_close() { +# Close focused window. Does NOT kill the child processes. +nowm_close() { xdotool getwindowfocus windowclose } -_quit() { +#TODO +# Does nothing? Idk. +nowm_quit() { xdotool getwindowfocus windowquit } -_kill() { +# Kill focused window. Kills the child processes too. +nowm_kill() { xdotool getwindowfocus windowkill } -_logout() { - kill "$NOWM_PID" -} -_help() { - cat << EOF -Usage: nowm [ACTION] +################ +# NoWM session # +################ -If no action is specified, then, if no graphical server is running, start one and NoWM, otherwise rerun autostart script and sleep -EOF +# Log out of the current session. +nowm_logout() { + kill "$NOWM_PID" } -# Fuck this shit. Seriously. I spent hours trying to figure out why the fuck my postlaunch file doesnt execute just to understand that I'm using startx /usr/bin/nowm instead of the dev version. I'm out. -noargs() { +# Start NoWM session or, if it is already running, rerun autostart script. +nowm_start() { if [ -z "${DISPLAY}" ]; then exec startx "$(which nowm)" else @@ -106,12 +161,34 @@ noargs() { fi } -valid="resize resize_relative move move_relative center snap pointer_focus select_focus close quit kill logout help" -if echo "${valid}" | grep -wq "${1}" ; then - _"${1}" "${@:2}" -elif [ -z "${1}" ]; then - noargs +# Display help message and exit. +nowm_help() { + cat << EOF +Usage: nowm [ACTION] + +If no action is specified, then, if no graphical server is running, start one and NoWM, otherwise rerun autostart script and sleep +EOF + exit "${1:-0}" +} + + +######## +# Main # +######## + +# String of space-separated valid arguments. +valid="resize resize_absolute resize_relative move move_absolute move_relative center snap pointer_focus raise select_focus close quit kill logout help" + +# If no argument is present, start NoWM session. +if [ -z "${1}" ]; then + nowm_start + +# If argument is present and valid, run the corresponding function. +elif echo "${valid}" | grep -wq "${1}" ; then + nowm_"${1}" "${@:2}" + +# If argument is present but invalid, display error and help messages else echo "Invalid command: '${1}'" - exit 1 + nowm_help 1 fi From 33641f620a37b348fb15631fba039b98a1281e53 Mon Sep 17 00:00:00 2001 From: xezo360hye Date: Mon, 31 Oct 2022 08:50:41 +0200 Subject: [PATCH 5/6] Small optimization changes Todo update man page --- src/nowm | 7 +++---- src/nowm.1 | 12 ++++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/nowm b/src/nowm index 5d95868..c9dacb8 100755 --- a/src/nowm +++ b/src/nowm @@ -49,6 +49,7 @@ nowm_resize() { fi } + ############### # Move window # ############### @@ -87,7 +88,7 @@ nowm_center() { nowm move "$(( (WIDTH - WINDOW_WIDTH) / 2 ))" "$(( (HEIGHT - WINDOW_HEIGHT) / 2 ))" } -# Place at the side of the screen (left, right, top, bottom). Includes resizing. +# Place at the side of the screen (left, right, top, bottom). nowm_snap() { eval "$(xdotool getwindowfocus getwindowgeometry --shell)" WINDOW_WIDTH="${WIDTH}" @@ -98,7 +99,6 @@ nowm_snap() { bottom) nowm move x "$(( HEIGHT - WINDOW_HEIGHT ))";; top) nowm move x 0 ;; right) nowm move "$(( WIDTH - WINDOW_WIDTH ))" y ;; - *) nowm move x y ;; esac } @@ -117,8 +117,7 @@ nowm_raise() { xdotool getwindowfocus windowraise } -#TODO -# Select window by clicking on it. Useless imo. +# Select window by clicking on it. Can be used if 'nowm_pointer_focus' does not work nowm_select_focus() { xdotool selectwindow windowfocus } diff --git a/src/nowm.1 b/src/nowm.1 index d71a322..2df7cfc 100644 --- a/src/nowm.1 +++ b/src/nowm.1 @@ -1,4 +1,4 @@ -.TH NOWM "1" "2022" "K4zoku" "User Commands" +.TH NOWM "1" "2022" "K4zoku" "NoWM manual" .SH NAME NoWM \- Managing window without a window manager .SH SYNOPSIS @@ -6,22 +6,22 @@ NoWM \- Managing window without a window manager .SH DESCRIPTION A dead simple tool to managing windows from the tty, written in shell script. .SH OPTIONS -\fBresize\fR \fBw h\fR +\fBresize w h\fR Shrink or grow the current window by the given w/h arguments .TP -\fBresize_relative\fR \fBw h\fR +\fBresize_relative w h\fR Shrink or grow the current window relatively by the given w/h arguments .TP -\fBmove\fR \fBx y\fR +\fBmove x y\fR Shift the current window by the given x/y coordinates .TP -\fBmove_relative\fR \fBx y\fR +\fBmove_relative x y\fR Shift the current window relatively by the given x/y coordinates .TP \fBcenter\fR Centers the current window. .TP -\fBsnap\fR \fB(top|bottom|left|right)\fR +\fBsnap (top|bottom|left|right)\fR Move and resize the current window to fill the DIRECTION half of the screen .TP \fBpointer_focus\fR From 02e3d07193d68ddd2ee9611cc7802aa6f07977fb Mon Sep 17 00:00:00 2001 From: xezo360hye Date: Thu, 17 Nov 2022 18:33:19 +0200 Subject: [PATCH 6/6] Manpage changes Added new sections `raise`, `move_absolute` and `resize_absolute`. Changed content inside `logout`, `move` and `resize`. Added line break in sections `close`, `kill` and `quit` --- src/nowm.1 | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/nowm.1 b/src/nowm.1 index 2df7cfc..a4f6667 100644 --- a/src/nowm.1 +++ b/src/nowm.1 @@ -6,20 +6,25 @@ NoWM \- Managing window without a window manager .SH DESCRIPTION A dead simple tool to managing windows from the tty, written in shell script. .SH OPTIONS -\fBresize w h\fR -Shrink or grow the current window by the given w/h arguments +.TP +\fBresize [+-]w [+-]h\fR +Shrink or grow the current window by the given w/h arguments. If you set + or - sign before w/h then they become relative coordinates, otherwise treating them as absolute +\fBresize_absolute w h\fR +Shrink or grow the current window by the given absolute w/h arguments .TP \fBresize_relative w h\fR -Shrink or grow the current window relatively by the given w/h arguments +Shrink or grow the current window by the given relative w/h arguments .TP \fBmove x y\fR -Shift the current window by the given x/y coordinates +Shift the current window by the given x/y coordinates. If you set + or - sign before x/y then they become relative coordinates, otherwise treating them as absolute +\fBmove_absolute x y\fR +Shift the current window by the given absolute x/y coordinates .TP \fBmove_relative x y\fR -Shift the current window relatively by the given x/y coordinates +Shift the current window by the given relative x/y coordinates .TP \fBcenter\fR -Centers the current window. +Move currently focused window to the center of the screen .TP \fBsnap (top|bottom|left|right)\fR Move and resize the current window to fill the DIRECTION half of the screen @@ -27,16 +32,22 @@ Move and resize the current window to fill the DIRECTION half of the screen \fBpointer_focus\fR Focus the window underneath the pointer .TP +\fBraise\fR +Raise currently focused window +.TP \fBselect_focus\fR -Focus selected window +Focus window using selection cursor .TP \fBclose\fR Destroy the window but will not try to kill the client controlling it +.TP \fBquit\fR Close window gracefully, this action sends a request, allowing the application to apply close confirmation mechanics +.TP \fBkill\fR Destroy the window and kill the client controlling it +.TP \fBlogout\fR -Log user out +Terminate current NoWM session (also kills applications) .SH REPORTING BUGS -Report bugs to https://github.com/K4zoku/nowm/issues +Report bugs to https://github.com/K4zoku/nowm/issues \ No newline at end of file