From 9692a006f33b8cfab9a4c623dc3c20150a58a4af Mon Sep 17 00:00:00 2001 From: Edward Zwart Date: Mon, 14 Jul 2025 16:31:28 -0700 Subject: [PATCH 01/10] Add basic linter github workflow --- .github/workflows/lint.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..0193420 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,24 @@ +name: Shell Script Linter + +on: + # Run on all pull requests and direct pushes to the main branch + pull_request: + push: + branches: + - main + +jobs: + # This is the job name that will appear in GitHub's status checks + shellcheck: + name: Run Shellcheck Linter + # Use the latest version of Ubuntu to run the job + runs-on: ubuntu-latest + steps: + # Step 1: Check out the repository's code so the workflow can access it + - uses: actions/checkout@v4 + + # Step 2: Run the shellcheck linter on the 'position' script + # If shellcheck finds any issues, it will exit with a non-zero code, + # which will cause this job to fail, blocking the PR merge. + - name: Run shellcheck + run: shellcheck ./position From 7bb748d98a22893d9c67f551dd1e1afe3db30f4b Mon Sep 17 00:00:00 2001 From: Edward Zwart Date: Mon, 14 Jul 2025 16:45:59 -0700 Subject: [PATCH 02/10] NT: Add branch naming workflow --- .github/workflows/branch-naming.yml | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/branch-naming.yml diff --git a/.github/workflows/branch-naming.yml b/.github/workflows/branch-naming.yml new file mode 100644 index 0000000..300e267 --- /dev/null +++ b/.github/workflows/branch-naming.yml @@ -0,0 +1,35 @@ +name: 'Branch Naming Police' + +on: + pull_request: + # Run this check when a PR is opened or when new commits are pushed to it + types: [opened, synchronize] + +jobs: + branch-naming-rules: + name: Check Branch Name + runs-on: ubuntu-latest + steps: + - name: Get branch name + # This step extracts the branch name from the PR event data + id: get_branch_name + run: echo "branch_name=${{ github.head_ref }}" >> $GITHUB_OUTPUT + + - name: Validate branch name + # This step uses the extracted branch name and tests it against the regex + run: | + BRANCH_NAME="${{ steps.get_branch_name.outputs.branch_name }}" + # This is the regex for your naming convention. + # It allows branches like: + # - issue/123-some-feature + # - issue/nt-another-feature + # It also allows 'main' and 'develop' to be valid source branches. + REGEX="^((issue\/(nt|\d+)-.+)|main|develop)$" + + if [[ $BRANCH_NAME =~ $REGEX ]]; then + echo "Branch name '$BRANCH_NAME' is valid." + else + echo "Branch name '$BRANCH_NAME' is not valid." + echo "Please name your branch according to the pattern: issue/nt-description or issue/123-description" + exit 1 + fi From 826d3f034409dcce791fb077741e1b068e1c3dc9 Mon Sep 17 00:00:00 2001 From: Edward Zwart Date: Mon, 14 Jul 2025 16:54:52 -0700 Subject: [PATCH 03/10] NT: Apply linter suggestions --- position | 115 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 70 insertions(+), 45 deletions(-) diff --git a/position b/position index 66c23ac..8ccc22e 100755 --- a/position +++ b/position @@ -34,19 +34,26 @@ save_config() { local name="$1" local window_data="$2" - local x=$(echo "$window_data" | jq -r .x) - local y=$(echo "$window_data" | jq -r .y) - local width=$(echo "$window_data" | jq -r .width) - local height=$(echo "$window_data" | jq -r .height) - local wmclass=$(echo "$window_data" | jq -r .wmClass) - local title=$(echo "$window_data" | jq -r .title) + local x + x=$(echo "$window_data" | jq -r .x) + local y + y=$(echo "$window_data" | jq -r .y) + local width + width=$(echo "$window_data" | jq -r .width) + local height + height=$(echo "$window_data" | jq -r .height) + local wmclass + wmclass=$(echo "$window_data" | jq -r .wmClass) + local title + title=$(echo "$window_data" | jq -r .title) # Extract title pattern - preserve dashes and underscores - local title_pattern=$(echo "$title" | awk '{print $1}' | sed 's/[^a-zA-Z0-9_-]//g') + local title_pattern + title_pattern=$(echo "$title" | awk '{print $1}' | sed 's/[^a-zA-Z0-9_-]//g') if [ -z "$title_pattern" ] || [ ${#title_pattern} -lt 2 ]; then echo -e "${YELLOW}Window title: $title${NC}" - read -p "Enter a title pattern to match (or press Enter to use WM_CLASS only): " user_pattern + read -r -p "Enter a title pattern to match (or press Enter to use WM_CLASS only): " user_pattern if [ -n "$user_pattern" ]; then title_pattern="$user_pattern" else @@ -57,7 +64,7 @@ save_config() { # Get a friendly name for the configuration echo -e "${YELLOW}Window title: $title${NC}" echo -e "${YELLOW}WM_CLASS: $wmclass${NC}" - read -p "Enter a friendly name for this configuration (default: $name): " friendly_name + read -r -p "Enter a friendly name for this configuration (default: $name): " friendly_name if [ -z "$friendly_name" ]; then friendly_name="$name" fi @@ -65,7 +72,7 @@ save_config() { # Remove existing configuration if it exists if grep -q "^\[$name\]" "$CONFIG_FILE" 2>/dev/null; then echo -e "${YELLOW}Updating existing configuration for '$name'...${NC}" - sed -i "/^\[$name\]/,/^\[/{ /^\[/!d; }" "$CONFIG_FILE" 2>/dev/null || true + sed -i "/^\[$name\]/,/^\[/{ /^\!/d; }" "$CONFIG_FILE" 2>/dev/null || true sed -i "/^\[$name\]/d" "$CONFIG_FILE" 2>/dev/null || true fi @@ -107,12 +114,18 @@ get_config() { fi # Extract values from INI section using a simpler approach - local x=$(sed -n "/^\[$app_name\]/,/^\[/p" "$CONFIG_FILE" | grep "^x = " | cut -d' ' -f3) - local y=$(sed -n "/^\[$app_name\]/,/^\[/p" "$CONFIG_FILE" | grep "^y = " | cut -d' ' -f3) - local width=$(sed -n "/^\[$app_name\]/,/^\[/p" "$CONFIG_FILE" | grep "^width = " | cut -d' ' -f3) - local height=$(sed -n "/^\[$app_name\]/,/^\[/p" "$CONFIG_FILE" | grep "^height = " | cut -d' ' -f3) - local wmclass=$(sed -n "/^\[$app_name\]/,/^\[/p" "$CONFIG_FILE" | grep "^wm_class = " | cut -d' ' -f3- | tr -d '"') - local title_pattern=$(sed -n "/^\[$app_name\]/,/^\[/p" "$CONFIG_FILE" | grep "^title_pattern = " | cut -d' ' -f3- | tr -d '"') + local x + x=$(sed -n "/^\[$app_name\]/,/^\[/p" "$CONFIG_FILE" | grep "^x = " | cut -d' ' -f3) + local y + y=$(sed -n "/^\[$app_name\]/,/^\[/p" "$CONFIG_FILE" | grep "^y = " | cut -d' ' -f3) + local width + width=$(sed -n "/^\[$app_name\]/,/^\[/p" "$CONFIG_FILE" | grep "^width = " | cut -d' ' -f3) + local height + height=$(sed -n "/^\[$app_name\]/,/^\[/p" "$CONFIG_FILE" | grep "^height = " | cut -d' ' -f3) + local wmclass + wmclass=$(sed -n "/^\[$app_name\]/,/^\[/p" "$CONFIG_FILE" | grep "^wm_class = " | cut -d' ' -f3- | tr -d '"') + local title_pattern + title_pattern=$(sed -n "/^\[$app_name\]/,/^\[/p" "$CONFIG_FILE" | grep "^title_pattern = " | cut -d' ' -f3- | tr -d '"') if [ -z "$x" ] || [ -z "$y" ] || [ -z "$width" ] || [ -z "$height" ] || [ -z "$wmclass" ]; then return 1 @@ -123,12 +136,14 @@ get_config() { # Function to get monitor info get_monitor_info() { - local raw_result=$(gdbus call --session \ + local raw_result + raw_result=$(gdbus call --session \ --dest org.gnome.Shell \ --object-path /org/gnome/Shell/WindowPositioner \ --method org.gnome.Shell.WindowPositioner.GetMonitorInfo 2>/dev/null) - local monitor_data=$(echo "$raw_result" | sed -n "s/^('\(.*\)',)$/\1/p") + local monitor_data + monitor_data=$(echo "$raw_result" | sed -n "s/^('\(.*\)',)$/\1/p") echo "$monitor_data" } @@ -145,15 +160,18 @@ capture_window() { echo -e "${GREEN}Capturing now!${NC}" - local window_data=$(gdbus call --session \ + local window_data + window_data=$(gdbus call --session \ --dest org.gnome.Shell \ --object-path /org/gnome/Shell/WindowPositioner \ --method org.gnome.Shell.WindowPositioner.GetActiveWindowInfo 2>/dev/null) - local clean_data=$(echo "$window_data" | sed -n "s/^('\(.*\)',)$/\1/p") + local clean_data + clean_data=$(echo "$window_data" | sed -n "s/^('\(.*\)',)$/\1/p") if echo "$clean_data" | jq -e .error > /dev/null 2>&1; then - local error=$(echo "$clean_data" | jq -r .error) + local error + error=$(echo "$clean_data" | jq -r .error) echo -e "${RED}Error: $error${NC}" exit 1 fi @@ -171,7 +189,7 @@ capture_window() { echo "$clean_data" | jq -r '"Size: " + (.width|tostring) + "x" + (.height|tostring)' echo - read -p "Enter a name for this window position: " name + read -r -p "Enter a name for this window position: " name if [ -z "$name" ]; then echo -e "${RED}No name provided. Cancelled.${NC}" @@ -184,9 +202,7 @@ capture_window() { # Function to position a window position_window() { local app_name="$1" - local config=$(get_config "$app_name") - - if [ $? -ne 0 ]; then + if ! config=$(get_config "$app_name"); then echo -e "${RED}Error: No configuration found for '$app_name'${NC}" echo -e "${YELLOW}Available configurations:${NC}" list_configs @@ -200,11 +216,12 @@ position_window() { if [ -n "$title_pattern" ]; then echo -e "${YELLOW}Positioning $app_name (${wmclass}, title containing '${title_pattern}') to ${x},${y} (${width}x${height})...${NC}" - local result=$(gdbus call --session \ + local result + result=$(gdbus call --session \ --dest org.gnome.Shell \ --object-path /org/gnome/Shell/WindowPositioner \ --method org.gnome.Shell.WindowPositioner.PositionWindowByClassAndTitle \ - "$wmclass" "$title_pattern" $x $y $width $height 2>/dev/null) + "$wmclass" "$title_pattern" "$x" "$y" "$width" "$height" 2>/dev/null) if [ -z "$result" ]; then echo -e "${YELLOW}Title matching not available, using WM_CLASS only...${NC}" @@ -212,16 +229,17 @@ position_window() { --dest org.gnome.Shell \ --object-path /org/gnome/Shell/WindowPositioner \ --method org.gnome.Shell.WindowPositioner.PositionWindowByClass \ - "$wmclass" $x $y $width $height 2>/dev/null) + "$wmclass" "$x" "$y" "$width" "$height" 2>/dev/null) fi else echo -e "${YELLOW}Positioning $app_name (${wmclass}) to ${x},${y} (${width}x${height})...${NC}" + local result result=$(gdbus call --session \ --dest org.gnome.Shell \ --object-path /org/gnome/Shell/WindowPositioner \ --method org.gnome.Shell.WindowPositioner.PositionWindowByClass \ - "$wmclass" $x $y $width $height 2>/dev/null) + "$wmclass" "$x" "$y" "$width" "$height" 2>/dev/null) fi @@ -259,22 +277,29 @@ edit_config() { echo # Get current values - local current_name=$(sed -n "/^\[$name\]/,/^\[/p" "$CONFIG_FILE" | grep "^name = " | cut -d' ' -f3- | tr -d '"') - local current_x=$(sed -n "/^\[$name\]/,/^\[/p" "$CONFIG_FILE" | grep "^x = " | cut -d' ' -f3) - local current_y=$(sed -n "/^\[$name\]/,/^\[/p" "$CONFIG_FILE" | grep "^y = " | cut -d' ' -f3) - local current_width=$(sed -n "/^\[$name\]/,/^\[/p" "$CONFIG_FILE" | grep "^width = " | cut -d' ' -f3) - local current_height=$(sed -n "/^\[$name\]/,/^\[/p" "$CONFIG_FILE" | grep "^height = " | cut -d' ' -f3) - local current_wmclass=$(sed -n "/^\[$name\]/,/^\[/p" "$CONFIG_FILE" | grep "^wm_class = " | cut -d' ' -f3- | tr -d '"') - local current_title_pattern=$(sed -n "/^\[$name\]/,/^\[/p" "$CONFIG_FILE" | grep "^title_pattern = " | cut -d' ' -f3- | tr -d '"') + local current_name + current_name=$(sed -n "/^\[$name\]/,/^\[/p" "$CONFIG_FILE" | grep "^name = " | cut -d' ' -f3- | tr -d '"') + local current_x + current_x=$(sed -n "/^\[$name\]/,/^\[/p" "$CONFIG_FILE" | grep "^x = " | cut -d' ' -f3) + local current_y + current_y=$(sed -n "/^\[$name\]/,/^\[/p" "$CONFIG_FILE" | grep "^y = " | cut -d' ' -f3) + local current_width + current_width=$(sed -n "/^\[$name\]/,/^\[/p" "$CONFIG_FILE" | grep "^width = " | cut -d' ' -f3) + local current_height + current_height=$(sed -n "/^\[$name\]/,/^\[/p" "$CONFIG_FILE" | grep "^height = " | cut -d' ' -f3) + local current_wmclass + current_wmclass=$(sed -n "/^\[$name\]/,/^\[/p" "$CONFIG_FILE" | grep "^wm_class = " | cut -d' ' -f3- | tr -d '"') + local current_title_pattern + current_title_pattern=$(sed -n "/^\[$name\]/,/^\[/p" "$CONFIG_FILE" | grep "^title_pattern = " | cut -d' ' -f3- | tr -d '"') # Prompt for new values - read -p "Name [$current_name]: " new_name - read -p "X position [$current_x]: " new_x - read -p "Y position [$current_y]: " new_y - read -p "Width [$current_width]: " new_width - read -p "Height [$current_height]: " new_height - read -p "WM Class [$current_wmclass]: " new_wmclass - read -p "Title Pattern [$current_title_pattern]: " new_title_pattern + read -r -p "Name [$current_name]: " new_name + read -r -p "X position [$current_x]: " new_x + read -r -p "Y position [$current_y]: " new_y + read -r -p "Width [$current_width]: " new_width + read -r -p "Height [$current_height]: " new_height + read -r -p "WM Class [$current_wmclass]: " new_wmclass + read -r -p "Title Pattern [$current_title_pattern]: " new_title_pattern # Use current values if no new value provided [ -z "$new_name" ] && new_name="$current_name" @@ -394,7 +419,7 @@ clear_all_configs() { fi echo -e "${RED}This will remove ALL saved window configurations.${NC}" - read -p "Are you sure? (y/N): " confirm + read -r -p "Are you sure? (y/N): " confirm if [[ "$confirm" =~ ^[Yy]$ ]]; then cat > "$CONFIG_FILE" << 'EOF' @@ -602,4 +627,4 @@ main() { esac } -main "$@" \ No newline at end of file +main "$@" From d99cb8b4cce48256f9dd037a275835b5b125fea8 Mon Sep 17 00:00:00 2001 From: Edward Zwart Date: Wed, 20 May 2026 10:00:54 -0700 Subject: [PATCH 04/10] Add workspace support to D-Bus extension - GetActiveWindowInfo now includes workspace number (1-based) in returned JSON - New PositionWindowByClassOnWorkspace method moves window to a target workspace before positioning it - New PositionWindowByClassAndTitleOnWorkspace does the same with title filtering - _moveWindow accepts an optional workspace parameter (0 = no change) Requires logout/login to take effect after deployment. --- GEMINI.md | 55 +++++++++++++++++++++++++++ extension.js | 105 ++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 154 insertions(+), 6 deletions(-) create mode 100644 GEMINI.md diff --git a/GEMINI.md b/GEMINI.md new file mode 100644 index 0000000..8fd1888 --- /dev/null +++ b/GEMINI.md @@ -0,0 +1,55 @@ +# Project Conventions + +This document outlines the key development conventions for this project to ensure consistency and clarity. + +## Branch Naming Strategy + +All development work should be done on branches that follow a specific naming convention. The format is `issue/-`. + +- **With an Issue:** `issue/42-login-security` +- **Without an Issue:** `issue/nt-shellcheck-config` + +## Local Commit Message Strategy + +All local commits must be prefixed with the relevant issue number or the `NT` identifier. + +- **Format:** `#: ` or `NT: ` +- **Example:** `#42: Add user model` or `NT: Configure linter` + +## Pull Request (PR) Naming Strategy + +PR titles are optimized for scannability and should be short and direct. Avoid words that don't provide any meaningful additional context. +For example, 'improve', 'update', 'refactor'. Simple noun phrases are often enough clarity to distinguish one PR from the others. + +- **With an Issue:** `#42: Login security` +- **Without an Issue:** `NT: Shellcheck configuration` + +## Final Commit Message Strategy + +We always use the "Squash and Merge" option on GitHub. This ensures that main is always buildable, runnable and releasable: a core feature of trunk-based development. +During squash and merge is where we create high-quality, permanent commit messages. The merger has two options: + +### 1. Manual Edit (for simple PRs) + +For straightforward changes, the merger can manually edit the commit message in the GitHub UI. The goal is to transform the PR title into a descriptive commit subject, often simply by adding a verb. + +- **PR Title:** `#42: Login security` +- **Final Commit Subject:** `#42: Improve login security` + +### 2. AI-Assisted Generation (for complex PRs) + +For more complex changes, the merger can ask Gemini to generate the complete, formatted squash commit message. + +- **Prompt:** `Generate the squash commit message for PR #.` +- **Action:** Gemini will provide the full subject and body. The merger will then copy this text and paste it into the squash-and-merge dialog in the GitHub UI. + +**Example AI-Generated Output:** +``` +#42: Improve login security + +Adds rate limiting to the authentication endpoint to prevent brute-force attacks. The configuration is stored in the new `security.yml` file. +``` + +## Development Philosophy + +This project is a live sandbox for experimenting with and documenting modern development practices, including AI tooling, workflow automation, and version control strategies. The conventions in this file are a living document. diff --git a/extension.js b/extension.js index 10f491a..4cbd5e3 100644 --- a/extension.js +++ b/extension.js @@ -31,6 +31,25 @@ const DBUS_INTERFACE_XML = ` + + + + + + + + + + + + + + + + + + + @@ -200,6 +219,7 @@ export default class WindowPositionerExtension { } const rect = window.get_frame_rect(); + const wsObj = window.get_workspace(); const windowData = { title: window.get_title() || "Unknown", x: rect.x, @@ -208,7 +228,8 @@ export default class WindowPositionerExtension { height: rect.height, maximized: window.get_maximized(), minimized: window.is_hidden(), - wmClass: window.get_wm_class() || "Unknown" + wmClass: window.get_wm_class() || "Unknown", + workspace: wsObj ? wsObj.index() + 1 : 1 }; console.log('[WindowPositioner] Returning window data:', JSON.stringify(windowData)); @@ -289,19 +310,91 @@ export default class WindowPositionerExtension { } } - // Private helper method to move/resize a window - _moveWindow(window, x, y, width, height) { + // Find window by WM_CLASS and move to workspace before positioning + PositionWindowByClassOnWorkspace(wmClass, workspace, x, y, width, height) { + try { + console.log(`[WindowPositioner] PositionWindowByClassOnWorkspace: "${wmClass}" ws=${workspace} to ${x},${y} ${width}x${height}`); + + const windows = global.get_window_actors(); + let targetWindow = null; + + for (const windowActor of windows) { + const window = windowActor.get_meta_window(); + const windowClass = window.get_wm_class(); + + if (windowClass && windowClass.toLowerCase() === wmClass.toLowerCase()) { + targetWindow = window; + break; + } + } + + if (!targetWindow) { + console.log(`[WindowPositioner] Window with WM_CLASS "${wmClass}" not found`); + this._debugAvailableWindows(); + return false; + } + + return this._moveWindow(targetWindow, x, y, width, height, workspace); + } catch (error) { + console.error('[WindowPositioner] Error in PositionWindowByClassOnWorkspace:', error); + return false; + } + } + + // Find window by WM_CLASS and title, move to workspace before positioning + PositionWindowByClassAndTitleOnWorkspace(wmClass, titlePattern, workspace, x, y, width, height) { try { + console.log(`[WindowPositioner] PositionWindowByClassAndTitleOnWorkspace: "${wmClass}" + "${titlePattern}" ws=${workspace} to ${x},${y} ${width}x${height}`); + + const windows = global.get_window_actors(); + let targetWindow = null; + + for (const windowActor of windows) { + const window = windowActor.get_meta_window(); + const windowClass = window.get_wm_class(); + const windowTitle = window.get_title(); + + if (windowClass && windowClass.toLowerCase() === wmClass.toLowerCase() && + windowTitle && windowTitle.toLowerCase().includes(titlePattern.toLowerCase())) { + targetWindow = window; + break; + } + } + + if (!targetWindow) { + console.log(`[WindowPositioner] Window with WM_CLASS "${wmClass}" and title containing "${titlePattern}" not found`); + this._debugAvailableWindows(); + return false; + } + + return this._moveWindow(targetWindow, x, y, width, height, workspace); + } catch (error) { + console.error('[WindowPositioner] Error in PositionWindowByClassAndTitleOnWorkspace:', error); + return false; + } + } + + // Private helper method to move/resize a window, optionally to a specific workspace (1-based) + _moveWindow(window, x, y, width, height, workspace = 0) { + try { + if (workspace > 0) { + const workspaceManager = global.workspace_manager; + const targetWorkspace = workspaceManager.get_workspace_by_index(workspace - 1); + if (targetWorkspace) { + window.change_workspace(targetWorkspace); + } + } + // Unmaximize the window first (both horizontally and vertically) window.unmaximize(3); - + // Move and resize the window window.move_resize_frame(false, x, y, width, height); - + const title = window.get_title(); const wmClass = window.get_wm_class(); console.log(`[WindowPositioner] Successfully positioned "${title}" (${wmClass}) to ${x},${y} ${width}x${height}`); - + return true; } catch (error) { console.error('[WindowPositioner] Error moving window:', error); From 4ee93c6784c8ffd6485f66ffd434289f98bf03d5 Mon Sep 17 00:00:00 2001 From: Edward Zwart Date: Wed, 20 May 2026 10:01:08 -0700 Subject: [PATCH 05/10] Add app/profile/workspace grouping and position all command Presets (formerly "configurations") now support three metadata fields: - workspace: which GNOME workspace the window belongs on (1-based, 0 = any) - app: app group for display grouping (e.g. chrome, terminal) - profile: use-case grouping (e.g. work, personal) These are captured automatically or prompted during `position capture` and editable via `position edit`. `position list` (and new alias `position ls`) now displays presets grouped by profile then app, with a footer reminding about `position all`. New `position all` command positions every saved preset at once, with optional `--profile` and `--app` filters. Failures are non-fatal and a summary is printed at the end. When a preset has a workspace set, the script calls the new workspace-aware D-Bus methods; falls back gracefully to the old methods if the extension has not been reloaded yet. --- position | 754 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 452 insertions(+), 302 deletions(-) diff --git a/position b/position index 8ccc22e..4d67120 100755 --- a/position +++ b/position @@ -1,7 +1,7 @@ #!/bin/bash # Universal Window Positioning Script -# Usage: position or position capture +# Usage: position or position capture SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" CONFIG_FILE="$SCRIPT_DIR/.window_positions.conf" @@ -23,34 +23,24 @@ check_extension() { return 0 } -# Function to load custom configurations -load_config() { - # INI-style config is parsed on-demand in get_config - return 0 -} - -# Function to save a new window configuration +# Function to save a new window preset save_config() { local name="$1" local window_data="$2" - - local x + + local x y width height wmclass title workspace x=$(echo "$window_data" | jq -r .x) - local y y=$(echo "$window_data" | jq -r .y) - local width width=$(echo "$window_data" | jq -r .width) - local height height=$(echo "$window_data" | jq -r .height) - local wmclass wmclass=$(echo "$window_data" | jq -r .wmClass) - local title title=$(echo "$window_data" | jq -r .title) - + workspace=$(echo "$window_data" | jq -r '.workspace // 0') + # Extract title pattern - preserve dashes and underscores local title_pattern title_pattern=$(echo "$title" | awk '{print $1}' | sed 's/[^a-zA-Z0-9_-]//g') - + if [ -z "$title_pattern" ] || [ ${#title_pattern} -lt 2 ]; then echo -e "${YELLOW}Window title: $title${NC}" read -r -p "Enter a title pattern to match (or press Enter to use WM_CLASS only): " user_pattern @@ -60,23 +50,38 @@ save_config() { title_pattern="" fi fi - - # Get a friendly name for the configuration + + # Get a friendly name for the preset echo -e "${YELLOW}Window title: $title${NC}" echo -e "${YELLOW}WM_CLASS: $wmclass${NC}" - read -r -p "Enter a friendly name for this configuration (default: $name): " friendly_name + read -r -p "Enter a friendly name for this preset (default: $name): " friendly_name if [ -z "$friendly_name" ]; then friendly_name="$name" fi - - # Remove existing configuration if it exists + + # Workspace (auto-captured, allow override) + read -r -p "Workspace [$workspace] (0 = any workspace): " new_workspace + if [ -n "$new_workspace" ]; then + workspace="$new_workspace" + fi + + # App group and profile metadata + read -r -p "App group (e.g. chrome, terminal) [optional]: " app_group + read -r -p "Profile (e.g. work, personal) [optional]: " profile_name + + # Remove existing preset if it exists if grep -q "^\[$name\]" "$CONFIG_FILE" 2>/dev/null; then - echo -e "${YELLOW}Updating existing configuration for '$name'...${NC}" - sed -i "/^\[$name\]/,/^\[/{ /^\!/d; }" "$CONFIG_FILE" 2>/dev/null || true - sed -i "/^\[$name\]/d" "$CONFIG_FILE" 2>/dev/null || true + echo -e "${YELLOW}Updating existing preset '$name'...${NC}" + awk -v section="[$name]" ' + BEGIN { in_section = 0 } + /^\[.*\]/ { + if ($0 == section) { in_section = 1; next } else { in_section = 0 } + } + !in_section + ' "$CONFIG_FILE" > "$CONFIG_FILE.tmp" && mv "$CONFIG_FILE.tmp" "$CONFIG_FILE" fi - - # Append new configuration in INI format + + # Append new preset in INI format { echo "" echo "[$name]" @@ -89,9 +94,18 @@ save_config() { if [ -n "$title_pattern" ]; then echo "title_pattern = \"$title_pattern\"" fi + if [ "$workspace" -gt 0 ] 2>/dev/null; then + echo "workspace = $workspace" + fi + if [ -n "$app_group" ]; then + echo "app = \"$app_group\"" + fi + if [ -n "$profile_name" ]; then + echo "profile = \"$profile_name\"" + fi } >> "$CONFIG_FILE" - - echo -e "${GREEN}Saved configuration for '$name' to $CONFIG_FILE${NC}" + + echo -e "${GREEN}Saved preset '$name' to $CONFIG_FILE${NC}" if [ -n "$title_pattern" ]; then echo -e "${CYAN}Will match windows with WM_CLASS '$wmclass' and title containing '$title_pattern'${NC}" else @@ -100,38 +114,37 @@ save_config() { echo -e "${CYAN}You can now use: position $name${NC}" } -# Function to get window configuration from INI format +# Function to get window preset from INI format +# Returns: x,y,width,height,wmclass,title_pattern,workspace get_config() { local app_name="$1" - + if [ ! -f "$CONFIG_FILE" ]; then return 1 fi - - # Check if section exists + if ! grep -q "^\[$app_name\]" "$CONFIG_FILE"; then return 1 fi - - # Extract values from INI section using a simpler approach - local x - x=$(sed -n "/^\[$app_name\]/,/^\[/p" "$CONFIG_FILE" | grep "^x = " | cut -d' ' -f3) - local y - y=$(sed -n "/^\[$app_name\]/,/^\[/p" "$CONFIG_FILE" | grep "^y = " | cut -d' ' -f3) - local width - width=$(sed -n "/^\[$app_name\]/,/^\[/p" "$CONFIG_FILE" | grep "^width = " | cut -d' ' -f3) - local height - height=$(sed -n "/^\[$app_name\]/,/^\[/p" "$CONFIG_FILE" | grep "^height = " | cut -d' ' -f3) - local wmclass - wmclass=$(sed -n "/^\[$app_name\]/,/^\[/p" "$CONFIG_FILE" | grep "^wm_class = " | cut -d' ' -f3- | tr -d '"') - local title_pattern - title_pattern=$(sed -n "/^\[$app_name\]/,/^\[/p" "$CONFIG_FILE" | grep "^title_pattern = " | cut -d' ' -f3- | tr -d '"') - + + local section_data + section_data=$(sed -n "/^\[$app_name\]/,/^\[/p" "$CONFIG_FILE") + + local x y width height wmclass title_pattern workspace + x=$(echo "$section_data" | grep "^x = " | cut -d' ' -f3) + y=$(echo "$section_data" | grep "^y = " | cut -d' ' -f3) + width=$(echo "$section_data" | grep "^width = " | cut -d' ' -f3) + height=$(echo "$section_data" | grep "^height = " | cut -d' ' -f3) + wmclass=$(echo "$section_data" | grep "^wm_class = " | cut -d' ' -f3- | tr -d '"') + title_pattern=$(echo "$section_data" | grep "^title_pattern = " | cut -d' ' -f3- | tr -d '"') + workspace=$(echo "$section_data" | grep "^workspace = " | cut -d' ' -f3) + workspace="${workspace:-0}" + if [ -z "$x" ] || [ -z "$y" ] || [ -z "$width" ] || [ -z "$height" ] || [ -z "$wmclass" ]; then return 1 fi - - echo "$x,$y,$width,$height,$wmclass,$title_pattern" + + echo "$x,$y,$width,$height,$wmclass,$title_pattern,$workspace" } # Function to get monitor info @@ -141,7 +154,7 @@ get_monitor_info() { --dest org.gnome.Shell \ --object-path /org/gnome/Shell/WindowPositioner \ --method org.gnome.Shell.WindowPositioner.GetMonitorInfo 2>/dev/null) - + local monitor_data monitor_data=$(echo "$raw_result" | sed -n "s/^('\(.*\)',)$/\1/p") echo "$monitor_data" @@ -151,78 +164,102 @@ get_monitor_info() { capture_window() { echo -e "${YELLOW}Preparing to capture window position...${NC}" echo -e "${CYAN}Switch to the window you want to capture and wait...${NC}" - - # Countdown timer + for i in 3 2 1; do echo -e "${YELLOW}Capturing in $i...${NC}" sleep 1 done - + echo -e "${GREEN}Capturing now!${NC}" - + local window_data window_data=$(gdbus call --session \ --dest org.gnome.Shell \ --object-path /org/gnome/Shell/WindowPositioner \ --method org.gnome.Shell.WindowPositioner.GetActiveWindowInfo 2>/dev/null) - + local clean_data clean_data=$(echo "$window_data" | sed -n "s/^('\(.*\)',)$/\1/p") - + if echo "$clean_data" | jq -e .error > /dev/null 2>&1; then local error error=$(echo "$clean_data" | jq -r .error) echo -e "${RED}Error: $error${NC}" exit 1 fi - + if ! echo "$clean_data" | jq . > /dev/null 2>&1; then echo -e "${RED}Error: Invalid JSON received${NC}" echo "Raw data: $clean_data" exit 1 fi - + echo -e "${CYAN}Window Details:${NC}" - echo "$clean_data" | jq -r '"Title: " + .title' - echo "$clean_data" | jq -r '"Class: " + .wmClass' - echo "$clean_data" | jq -r '"Position: " + (.x|tostring) + "," + (.y|tostring)' - echo "$clean_data" | jq -r '"Size: " + (.width|tostring) + "x" + (.height|tostring)' + echo "$clean_data" | jq -r '"Title: " + .title' + echo "$clean_data" | jq -r '"Class: " + .wmClass' + echo "$clean_data" | jq -r '"Position: " + (.x|tostring) + "," + (.y|tostring)' + echo "$clean_data" | jq -r '"Size: " + (.width|tostring) + "x" + (.height|tostring)' + echo "$clean_data" | jq -r '"Workspace: " + ((.workspace // 1) | tostring)' echo - - read -r -p "Enter a name for this window position: " name - + + read -r -p "Enter a name for this preset: " name + if [ -z "$name" ]; then echo -e "${RED}No name provided. Cancelled.${NC}" exit 1 fi - + save_config "$name" "$clean_data" } # Function to position a window +# $1: preset name +# $2: --no-exit (optional) — return instead of exit on failure (used by position all) position_window() { local app_name="$1" + local no_exit="${2:-}" + + local config if ! config=$(get_config "$app_name"); then - echo -e "${RED}Error: No configuration found for '$app_name'${NC}" - echo -e "${YELLOW}Available configurations:${NC}" - list_configs - echo -e "${CYAN}Use 'position capture' to create a new configuration${NC}" - exit 1 + echo -e "${RED}Error: No preset found for '$app_name'${NC}" + if [ -z "$no_exit" ]; then + echo -e "${YELLOW}Available presets:${NC}" + list_configs + echo -e "${CYAN}Use 'position capture' to create a new preset${NC}" + exit 1 + fi + return 1 + fi + + local x y width height wmclass title_pattern workspace + IFS=',' read -r x y width height wmclass title_pattern workspace <<< "$config" + workspace="${workspace:-0}" + + local use_workspace="" + if [[ "$workspace" =~ ^[1-9][0-9]*$ ]]; then + use_workspace="$workspace" fi - - IFS=',' read -r x y width height wmclass title_pattern <<< "$config" - - # Position using extension method + + local result if [ -n "$title_pattern" ]; then echo -e "${YELLOW}Positioning $app_name (${wmclass}, title containing '${title_pattern}') to ${x},${y} (${width}x${height})...${NC}" - - local result - result=$(gdbus call --session \ - --dest org.gnome.Shell \ - --object-path /org/gnome/Shell/WindowPositioner \ - --method org.gnome.Shell.WindowPositioner.PositionWindowByClassAndTitle \ - "$wmclass" "$title_pattern" "$x" "$y" "$width" "$height" 2>/dev/null) - + + if [ -n "$use_workspace" ]; then + result=$(gdbus call --session \ + --dest org.gnome.Shell \ + --object-path /org/gnome/Shell/WindowPositioner \ + --method org.gnome.Shell.WindowPositioner.PositionWindowByClassAndTitleOnWorkspace \ + "$wmclass" "$title_pattern" "$use_workspace" "$x" "$y" "$width" "$height" 2>/dev/null) + fi + + if [ -z "$result" ]; then + result=$(gdbus call --session \ + --dest org.gnome.Shell \ + --object-path /org/gnome/Shell/WindowPositioner \ + --method org.gnome.Shell.WindowPositioner.PositionWindowByClassAndTitle \ + "$wmclass" "$title_pattern" "$x" "$y" "$width" "$height" 2>/dev/null) + fi + if [ -z "$result" ]; then echo -e "${YELLOW}Title matching not available, using WM_CLASS only...${NC}" result=$(gdbus call --session \ @@ -233,18 +270,27 @@ position_window() { fi else echo -e "${YELLOW}Positioning $app_name (${wmclass}) to ${x},${y} (${width}x${height})...${NC}" - - local result - result=$(gdbus call --session \ - --dest org.gnome.Shell \ - --object-path /org/gnome/Shell/WindowPositioner \ - --method org.gnome.Shell.WindowPositioner.PositionWindowByClass \ - "$wmclass" "$x" "$y" "$width" "$height" 2>/dev/null) + + if [ -n "$use_workspace" ]; then + result=$(gdbus call --session \ + --dest org.gnome.Shell \ + --object-path /org/gnome/Shell/WindowPositioner \ + --method org.gnome.Shell.WindowPositioner.PositionWindowByClassOnWorkspace \ + "$wmclass" "$use_workspace" "$x" "$y" "$width" "$height" 2>/dev/null) + fi + + if [ -z "$result" ]; then + result=$(gdbus call --session \ + --dest org.gnome.Shell \ + --object-path /org/gnome/Shell/WindowPositioner \ + --method org.gnome.Shell.WindowPositioner.PositionWindowByClass \ + "$wmclass" "$x" "$y" "$width" "$height" 2>/dev/null) + fi fi - - + if echo "$result" | grep -q "true"; then echo -e "${GREEN}Successfully positioned $app_name${NC}" + return 0 else echo -e "${RED}Failed to position $app_name. Is the application running?${NC}" if [ -n "$title_pattern" ]; then @@ -252,47 +298,129 @@ position_window() { else echo -e "${YELLOW}Make sure you have a window with WM_CLASS '$wmclass'${NC}" fi - exit 1 + if [ -z "$no_exit" ]; then exit 1; else return 1; fi + fi +} + +# Function to position all presets, with optional --profile and --app filters +position_all() { + local filter_profile="" + local filter_app="" + + while [[ $# -gt 0 ]]; do + case "$1" in + --profile) filter_profile="$2"; shift 2 ;; + --app) filter_app="$2"; shift 2 ;; + *) echo -e "${RED}Unknown option: $1${NC}" + echo -e "${CYAN}Usage: position all [--profile ] [--app ]${NC}" + exit 1 ;; + esac + done + + if [ ! -f "$CONFIG_FILE" ] || [ ! -s "$CONFIG_FILE" ]; then + echo -e "${YELLOW}No presets saved yet.${NC}" + return 0 + fi + + # Collect section names with their app/profile metadata + local sections + sections=$(awk ' + BEGIN { section=""; app=""; profile="" } + /^\[.*\]/ { + if (section != "") { + printf "%s|%s|%s\n", section, + (app == "" ? "" : app), + (profile == "" ? "" : profile) + } + section = substr($0, 2, length($0)-2) + app = ""; profile = "" + } + /^app = / { app = substr($0, 7); gsub(/^"|"$/, "", app) } + /^profile = / { profile = substr($0, 11); gsub(/^"|"$/, "", profile) } + END { + if (section != "") { + printf "%s|%s|%s\n", section, + (app == "" ? "" : app), + (profile == "" ? "" : profile) + } + } + ' "$CONFIG_FILE") + + if [ -n "$filter_profile" ]; then + echo -e "${CYAN}Positioning all presets for profile: ${YELLOW}$filter_profile${NC}" + elif [ -n "$filter_app" ]; then + echo -e "${CYAN}Positioning all presets for app: ${YELLOW}$filter_app${NC}" + else + echo -e "${CYAN}Positioning all presets...${NC}" + fi + echo + + local count=0 success=0 + local failed=() + + while IFS='|' read -r section app profile; do + [ -z "$section" ] && continue + if [ -n "$filter_profile" ] && [ "$profile" != "$filter_profile" ]; then + continue + fi + if [ -n "$filter_app" ] && [ "$app" != "$filter_app" ]; then + continue + fi + + count=$((count + 1)) + if position_window "$section" --no-exit; then + success=$((success + 1)) + else + failed+=("$section") + fi + done <<< "$sections" + + echo + if [ "$count" -eq 0 ]; then + echo -e "${YELLOW}No matching presets found.${NC}" + else + echo -e "${CYAN}Result: ${GREEN}$success${CYAN}/${count} windows positioned${NC}" + if [ ${#failed[@]} -gt 0 ]; then + echo -e "${YELLOW}Not positioned (window not running?): ${failed[*]}${NC}" + fi fi } -# Function to edit an existing configuration +# Function to edit an existing preset edit_config() { local name="$1" - + if ! grep -q "^\[$name\]" "$CONFIG_FILE" 2>/dev/null; then - echo -e "${RED}Configuration '$name' not found${NC}" - echo -e "${YELLOW}Available configurations:${NC}" - awk ' - /^\[.*\]/ { - section = substr($0, 2, length($0)-2) - printf " %s\n", section - } - ' "$CONFIG_FILE" | sort + echo -e "${RED}Preset '$name' not found${NC}" + echo -e "${YELLOW}Available presets:${NC}" + list_configs return 1 fi - - echo -e "${CYAN}Editing configuration: $name${NC}" + + echo -e "${CYAN}Editing preset: $name${NC}" echo -e "${YELLOW}Press Enter to keep current value, or type new value${NC}" echo - - # Get current values - local current_name - current_name=$(sed -n "/^\[$name\]/,/^\[/p" "$CONFIG_FILE" | grep "^name = " | cut -d' ' -f3- | tr -d '"') - local current_x - current_x=$(sed -n "/^\[$name\]/,/^\[/p" "$CONFIG_FILE" | grep "^x = " | cut -d' ' -f3) - local current_y - current_y=$(sed -n "/^\[$name\]/,/^\[/p" "$CONFIG_FILE" | grep "^y = " | cut -d' ' -f3) - local current_width - current_width=$(sed -n "/^\[$name\]/,/^\[/p" "$CONFIG_FILE" | grep "^width = " | cut -d' ' -f3) - local current_height - current_height=$(sed -n "/^\[$name\]/,/^\[/p" "$CONFIG_FILE" | grep "^height = " | cut -d' ' -f3) - local current_wmclass - current_wmclass=$(sed -n "/^\[$name\]/,/^\[/p" "$CONFIG_FILE" | grep "^wm_class = " | cut -d' ' -f3- | tr -d '"') - local current_title_pattern - current_title_pattern=$(sed -n "/^\[$name\]/,/^\[/p" "$CONFIG_FILE" | grep "^title_pattern = " | cut -d' ' -f3- | tr -d '"') - - # Prompt for new values + + local section_data + section_data=$(sed -n "/^\[$name\]/,/^\[/p" "$CONFIG_FILE") + + local current_name current_x current_y current_width current_height + local current_wmclass current_title_pattern current_workspace current_app current_profile + + current_name=$(echo "$section_data" | grep "^name = " | cut -d' ' -f3- | tr -d '"') + current_x=$(echo "$section_data" | grep "^x = " | cut -d' ' -f3) + current_y=$(echo "$section_data" | grep "^y = " | cut -d' ' -f3) + current_width=$(echo "$section_data" | grep "^width = " | cut -d' ' -f3) + current_height=$(echo "$section_data" | grep "^height = " | cut -d' ' -f3) + current_wmclass=$(echo "$section_data" | grep "^wm_class = " | cut -d' ' -f3- | tr -d '"') + current_title_pattern=$(echo "$section_data" | grep "^title_pattern = " | cut -d' ' -f3- | tr -d '"') + current_workspace=$(echo "$section_data" | grep "^workspace = " | cut -d' ' -f3) + current_app=$(echo "$section_data" | grep "^app = " | cut -d' ' -f3- | tr -d '"') + current_profile=$(echo "$section_data" | grep "^profile = " | cut -d' ' -f3- | tr -d '"') + + local new_name new_x new_y new_width new_height + local new_wmclass new_title_pattern new_workspace new_app new_profile + read -r -p "Name [$current_name]: " new_name read -r -p "X position [$current_x]: " new_x read -r -p "Y position [$current_y]: " new_y @@ -300,40 +428,38 @@ edit_config() { read -r -p "Height [$current_height]: " new_height read -r -p "WM Class [$current_wmclass]: " new_wmclass read -r -p "Title Pattern [$current_title_pattern]: " new_title_pattern - - # Use current values if no new value provided - [ -z "$new_name" ] && new_name="$current_name" - [ -z "$new_x" ] && new_x="$current_x" - [ -z "$new_y" ] && new_y="$current_y" - [ -z "$new_width" ] && new_width="$current_width" - [ -z "$new_height" ] && new_height="$current_height" - [ -z "$new_wmclass" ] && new_wmclass="$current_wmclass" + read -r -p "Workspace [$current_workspace] (0 = any): " new_workspace + read -r -p "App group [$current_app]: " new_app + read -r -p "Profile [$current_profile]: " new_profile + + [ -z "$new_name" ] && new_name="$current_name" + [ -z "$new_x" ] && new_x="$current_x" + [ -z "$new_y" ] && new_y="$current_y" + [ -z "$new_width" ] && new_width="$current_width" + [ -z "$new_height" ] && new_height="$current_height" + [ -z "$new_wmclass" ] && new_wmclass="$current_wmclass" [ -z "$new_title_pattern" ] && new_title_pattern="$current_title_pattern" - - # Validate numeric inputs - if ! [[ "$new_x" =~ ^[0-9]+$ ]] || ! [[ "$new_y" =~ ^[0-9]+$ ]] || ! [[ "$new_width" =~ ^[0-9]+$ ]] || ! [[ "$new_height" =~ ^[0-9]+$ ]]; then + [ -z "$new_workspace" ] && new_workspace="$current_workspace" + [ -z "$new_app" ] && new_app="$current_app" + [ -z "$new_profile" ] && new_profile="$current_profile" + + if ! [[ "$new_x" =~ ^[0-9]+$ ]] || ! [[ "$new_y" =~ ^[0-9]+$ ]] || \ + ! [[ "$new_width" =~ ^[0-9]+$ ]] || ! [[ "$new_height" =~ ^[0-9]+$ ]]; then echo -e "${RED}Error: Position and size values must be numbers${NC}" return 1 fi - + echo - echo -e "${YELLOW}Updating configuration...${NC}" - - # Remove existing configuration + echo -e "${YELLOW}Updating preset...${NC}" + awk -v section="[$name]" ' BEGIN { in_section = 0 } /^\[.*\]/ { - if ($0 == section) { - in_section = 1 - next - } else { - in_section = 0 - } + if ($0 == section) { in_section = 1; next } else { in_section = 0 } } !in_section ' "$CONFIG_FILE" > "$CONFIG_FILE.tmp" - - # Add updated configuration + { echo "" echo "[$name]" @@ -346,9 +472,17 @@ edit_config() { if [ -n "$new_title_pattern" ]; then echo "title_pattern = \"$new_title_pattern\"" fi + if [ "$new_workspace" -gt 0 ] 2>/dev/null; then + echo "workspace = $new_workspace" + fi + if [ -n "$new_app" ]; then + echo "app = \"$new_app\"" + fi + if [ -n "$new_profile" ]; then + echo "profile = \"$new_profile\"" + fi } >> "$CONFIG_FILE.tmp" - - # Clean up spacing and finalize + awk ' BEGIN { prev_line = "" } /^\[.*\]/ { @@ -357,43 +491,32 @@ edit_config() { prev_line = $0 next } - { - print - prev_line = $0 - } + { print; prev_line = $0 } ' "$CONFIG_FILE.tmp" > "$CONFIG_FILE" && rm "$CONFIG_FILE.tmp" - - echo -e "${GREEN}Configuration '$name' updated successfully${NC}" + + echo -e "${GREEN}Preset '$name' updated successfully${NC}" echo -e "${CYAN}You can now use: position $name${NC}" } -# Function to clear a specific configuration +# Function to clear a specific preset clear_config() { local name="$1" - + if ! grep -q "^\[$name\]" "$CONFIG_FILE" 2>/dev/null; then - echo -e "${RED}Configuration '$name' not found${NC}" + echo -e "${RED}Preset '$name' not found${NC}" return 1 fi - - echo -e "${YELLOW}Removing configuration for '$name'...${NC}" - - # Remove the section and its content, then clean up spacing - # First remove the section + + echo -e "${YELLOW}Removing preset '$name'...${NC}" + awk -v section="[$name]" ' BEGIN { in_section = 0 } /^\[.*\]/ { - if ($0 == section) { - in_section = 1 - next - } else { - in_section = 0 - } + if ($0 == section) { in_section = 1; next } else { in_section = 0 } } !in_section ' "$CONFIG_FILE" > "$CONFIG_FILE.tmp" - - # Then ensure proper spacing between sections (empty line before each [section]) + awk ' BEGIN { prev_line = "" } /^\[.*\]/ { @@ -402,144 +525,165 @@ clear_config() { prev_line = $0 next } - { - print - prev_line = $0 - } + { print; prev_line = $0 } ' "$CONFIG_FILE.tmp" > "$CONFIG_FILE" && rm "$CONFIG_FILE.tmp" - - echo -e "${GREEN}Removed configuration for '$name'${NC}" + + echo -e "${GREEN}Removed preset '$name'${NC}" } -# Function to clear all configurations +# Function to clear all presets clear_all_configs() { if [ ! -f "$CONFIG_FILE" ] || [ ! -s "$CONFIG_FILE" ]; then - echo -e "${YELLOW}No configurations to clear${NC}" + echo -e "${YELLOW}No presets to clear${NC}" return 0 fi - - echo -e "${RED}This will remove ALL saved window configurations.${NC}" + + echo -e "${RED}This will remove ALL saved presets.${NC}" read -r -p "Are you sure? (y/N): " confirm - + if [[ "$confirm" =~ ^[Yy]$ ]]; then cat > "$CONFIG_FILE" << 'EOF' # Window Positioning Configuration EOF - echo -e "${GREEN}All configurations cleared${NC}" + echo -e "${GREEN}All presets cleared${NC}" else echo -e "${CYAN}Cancelled${NC}" fi } -# Function to list available configurations +# Function to list available presets list_configs() { local show_full="${1:-}" local target="${2:-}" - - # If target is specified, automatically enable full details + if [ -n "$target" ]; then show_full="--full" fi - - if [ -f "$CONFIG_FILE" ] && [ -s "$CONFIG_FILE" ]; then - if [ "$show_full" = "--full" ]; then - echo -e "${CYAN}Saved configurations (detailed):${NC}" - echo - - # Show full details for each configuration - if [ -n "$target" ]; then - # Show only the specified target - if grep -q "^\[$target\]" "$CONFIG_FILE"; then - awk -v target="$target" ' - /^\[.*\]/ { - section = substr($0, 2, length($0)-2) - if (section == target) { - in_target = 1 - printf " %s:\n", section - } else { - in_target = 0 - } - } - in_target && /^name = / { - name = substr($0, 8) - gsub(/^"|"$/, "", name) - printf " Name: %s\n", name - } - in_target && /^x = / { printf " Position: %s", substr($0, 5) } - in_target && /^y = / { printf ",%s\n", substr($0, 5) } - in_target && /^width = / { printf " Size: %s", substr($0, 9) } - in_target && /^height = / { printf "x%s\n", substr($0, 10) } - in_target && /^wm_class = / { - wmclass = substr($0, 12) - gsub(/^"|"$/, "", wmclass) - printf " WM Class: %s\n", wmclass - } - in_target && /^title_pattern = / { - pattern = substr($0, 17) - gsub(/^"|"$/, "", pattern) - printf " Title Pattern: %s\n", pattern - } - ' "$CONFIG_FILE" - else - echo -e "${RED}Configuration '$target' not found${NC}" - echo -e "${YELLOW}Available configurations:${NC}" - awk ' - /^\[.*\]/ { - section = substr($0, 2, length($0)-2) - printf " %s\n", section - } - ' "$CONFIG_FILE" | sort - fi - else - # Show all configurations - awk ' - /^\[.*\]/ { - if (section != "") print "" - section = substr($0, 2, length($0)-2) - printf " %s:\n", section - } - /^name = / { - name = substr($0, 8) - gsub(/^"|"$/, "", name) - printf " Name: %s\n", name - } - /^x = / { printf " Position: %s", substr($0, 5) } - /^y = / { printf ",%s\n", substr($0, 5) } - /^width = / { printf " Size: %s", substr($0, 9) } - /^height = / { printf "x%s\n", substr($0, 10) } - /^wm_class = / { - wmclass = substr($0, 12) - gsub(/^"|"$/, "", wmclass) - printf " WM Class: %s\n", wmclass - } - /^title_pattern = / { - pattern = substr($0, 17) - gsub(/^"|"$/, "", pattern) - printf " Title Pattern: %s\n", pattern - } - ' "$CONFIG_FILE" + + if [ ! -f "$CONFIG_FILE" ] || [ ! -s "$CONFIG_FILE" ]; then + echo -e "${YELLOW}No presets saved yet.${NC}" + echo -e "${CYAN}Use 'position capture' to create your first preset${NC}" + return + fi + + # Check if there are any sections + if ! grep -q "^\[" "$CONFIG_FILE"; then + echo -e "${YELLOW}No presets saved yet.${NC}" + echo -e "${CYAN}Use 'position capture' to create your first preset${NC}" + return + fi + + if [ "$show_full" = "--full" ]; then + echo -e "${CYAN}Saved presets (detailed):${NC}" + echo + + if [ -n "$target" ]; then + if ! grep -q "^\[$target\]" "$CONFIG_FILE"; then + echo -e "${RED}Preset '$target' not found${NC}" + echo -e "${YELLOW}Available presets:${NC}" + list_configs + return fi + awk -v target="$target" ' + /^\[.*\]/ { + section = substr($0, 2, length($0)-2) + in_target = (section == target) + if (in_target) printf " %s:\n", section + } + in_target && /^name = / { v=substr($0,8); gsub(/^"|"$/,"",v); printf " Name: %s\n", v } + in_target && /^x = / { printf " Position: %s", substr($0,5) } + in_target && /^y = / { printf ",%s\n", substr($0,5) } + in_target && /^width = / { printf " Size: %s", substr($0,9) } + in_target && /^height = / { printf "x%s\n", substr($0,10) } + in_target && /^wm_class = / { v=substr($0,12); gsub(/^"|"$/,"",v); printf " WM Class: %s\n", v } + in_target && /^title_pattern = / { v=substr($0,17); gsub(/^"|"$/,"",v); printf " Title Pattern: %s\n", v } + in_target && /^workspace = / { printf " Workspace: %s\n", substr($0,13) } + in_target && /^app = / { v=substr($0,7); gsub(/^"|"$/,"",v); printf " App: %s\n", v } + in_target && /^profile = / { v=substr($0,11); gsub(/^"|"$/,"",v); printf " Profile: %s\n", v } + ' "$CONFIG_FILE" else - echo -e "${CYAN}Saved configurations:${NC}" - - # Extract section names and their friendly names awk ' - /^\[.*\]/ { + /^\[.*\]/ { + if (section != "") print "" section = substr($0, 2, length($0)-2) - name = "" + printf " %s:\n", section } - /^name = / { - name = substr($0, 8) - gsub(/^"|"|$/, "", name) - printf " %-24s %s\n", section, name - } - ' "$CONFIG_FILE" | sort + /^name = / { v=substr($0,8); gsub(/^"|"$/,"",v); printf " Name: %s\n", v } + /^x = / { printf " Position: %s", substr($0,5) } + /^y = / { printf ",%s\n", substr($0,5) } + /^width = / { printf " Size: %s", substr($0,9) } + /^height = / { printf "x%s\n", substr($0,10) } + /^wm_class = / { v=substr($0,12); gsub(/^"|"$/,"",v); printf " WM Class: %s\n", v } + /^title_pattern = / { v=substr($0,17); gsub(/^"|"$/,"",v); printf " Title Pattern: %s\n", v } + /^workspace = / { printf " Workspace: %s\n", substr($0,13) } + /^app = / { v=substr($0,7); gsub(/^"|"$/,"",v); printf " App: %s\n", v } + /^profile = / { v=substr($0,11); gsub(/^"|"$/,"",v); printf " Profile: %s\n", v } + ' "$CONFIG_FILE" fi - else - echo -e "${YELLOW}No configurations saved yet.${NC}" - echo -e "${CYAN}Use 'position capture' to create your first configuration${NC}" + return fi + + # Compact grouped view: group by profile, then app + local tmpdata + tmpdata=$(awk ' + BEGIN { section=""; app=""; profile=""; name="" } + /^\[.*\]/ { + if (section != "") { + printf "%s|%s|%s|%s\n", + (profile == "" ? "(ungrouped)" : profile), + (app == "" ? "" : app), + section, name + } + section = substr($0, 2, length($0)-2) + app = ""; profile = ""; name = "" + } + /^name = / { name = substr($0,8); gsub(/^"|"$/, "", name) } + /^app = / { app = substr($0,7); gsub(/^"|"$/, "", app) } + /^profile = / { profile = substr($0,11); gsub(/^"|"$/, "", profile) } + END { + if (section != "") { + printf "%s|%s|%s|%s\n", + (profile == "" ? "(ungrouped)" : profile), + (app == "" ? "" : app), + section, name + } + } + ' "$CONFIG_FILE" | sort) + + if [ -z "$tmpdata" ]; then + echo -e "${YELLOW}No presets saved yet.${NC}" + echo -e "${CYAN}Use 'position capture' to create your first preset${NC}" + return + fi + + echo -e "${CYAN}Saved presets:${NC}" + + local prev_profile="" prev_app="" + while IFS='|' read -r profile app section name; do + if [ "$profile" != "$prev_profile" ]; then + echo + echo -e " ${YELLOW}[$profile]${NC}" + prev_profile="$profile" + prev_app="" + fi + if [ "$app" != "$prev_app" ]; then + if [ -n "$app" ]; then + echo -e " ${CYAN}$app${NC}" + fi + prev_app="$app" + fi + if [ -n "$app" ]; then + printf " %-24s %s\n" "$section" "$name" + else + printf " %-24s %s\n" "$section" "$name" + fi + done <<< "$tmpdata" + + echo + echo -e " Run ${GREEN}position all${NC} to position all windows at once." + echo -e " Run ${GREEN}position all --profile ${NC} to position only one profile." + echo -e " Run ${GREEN}position ls${NC} as an alias for this command." } # Function to show usage @@ -547,66 +691,72 @@ show_usage() { echo "Universal Window Positioning Tool" echo "" echo "Usage:" - echo " position Position a configured application" - echo " position capture Capture current window position" - echo " position list List all configured applications" - echo " position list --full List configurations with full details" - echo " position list Show detailed info for specific configuration" - echo " position edit Edit an existing configuration" - echo " position clear Remove a specific configuration" - echo " position clear-all Remove all configurations" - echo " position debug Show all windows with WM_CLASS values" - echo " position --help Show this help" + echo " position Position a saved preset" + echo " position all Position all saved presets" + echo " position all --profile

Position presets for a profile" + echo " position all --app Position presets for an app group" + echo " position capture Capture current window as a new preset" + echo " position list List all presets (grouped by profile/app)" + echo " position ls Alias for 'position list'" + echo " position list --full List presets with full details" + echo " position list Show detailed info for a specific preset" + echo " position edit Edit an existing preset" + echo " position clear Remove a specific preset" + echo " position clear-all Remove all presets" + echo " position debug Show all windows with WM_CLASS values" + echo " position --help Show this help" echo "" echo "Examples:" - echo " position keepass Position KeePassXC" - echo " position list Show saved configurations" - echo " position list phpstorm Show detailed info for phpstorm config" - echo " position edit phpstorm Edit phpstorm configuration" - echo " position capture Save current window position" + echo " position keepass Position KeePassXC" + echo " position all Position all saved windows" + echo " position all --profile work Position only work-profile windows" + echo " position list Show saved presets grouped by profile" + echo " position list phpstorm Show detailed info for phpstorm preset" + echo " position edit phpstorm Edit phpstorm preset" + echo " position capture Save current window position as a preset" echo "" } # Main execution main() { - # Check dependencies if ! command -v jq &> /dev/null; then echo -e "${RED}Error: jq is required but not installed${NC}" echo "Install with: sudo apt install jq" exit 1 fi - - load_config + check_extension - + case "${1:-help}" in "capture") capture_window ;; - "list") + "list"|"ls") if [ "$2" = "--full" ]; then list_configs --full elif [ -n "$2" ]; then - # Second argument is a target name list_configs --full "$2" else list_configs fi ;; + "all") + position_all "${@:2}" + ;; "edit") if [ -n "$2" ]; then edit_config "$2" else - echo -e "${RED}Usage: position edit ${NC}" + echo -e "${RED}Usage: position edit ${NC}" echo -e "${CYAN}Example: position edit phpstorm${NC}" - echo -e "${CYAN}Use 'position list' to see available configurations${NC}" + echo -e "${CYAN}Use 'position list' to see available presets${NC}" fi ;; "clear") if [ -n "$2" ]; then clear_config "$2" else - echo -e "${RED}Usage: position clear ${NC}" + echo -e "${RED}Usage: position clear ${NC}" echo -e "${CYAN}Example: position clear keepass${NC}" echo -e "${CYAN}Use 'position clear-all' to remove everything${NC}" fi From a418b028b8b3b7db95c86d68731a27e73418f964 Mon Sep 17 00:00:00 2001 From: Edward Zwart Date: Wed, 20 May 2026 10:31:44 -0700 Subject: [PATCH 06/10] Map workspace=0 to sticky (pin window across all workspaces) In the extension, _moveWindow now calls window.stick() when workspace is 0, and window.unstick() before change_workspace() when workspace is positive. GetActiveWindowInfo includes a sticky field in the returned JSON. In the position script, sticky windows auto-capture as workspace=0 during capture. The workspace prompt adapts its hint based on whether the window is sticky. The write condition now uses a regex so workspace=0 is written to config (previously the > 0 guard suppressed it). list --full displays workspace 0 as "all (sticky)". --- extension.js | 8 ++++++-- position | 26 +++++++++++++++++--------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/extension.js b/extension.js index 4cbd5e3..e2e4c10 100644 --- a/extension.js +++ b/extension.js @@ -229,7 +229,8 @@ export default class WindowPositionerExtension { maximized: window.get_maximized(), minimized: window.is_hidden(), wmClass: window.get_wm_class() || "Unknown", - workspace: wsObj ? wsObj.index() + 1 : 1 + workspace: wsObj ? wsObj.index() + 1 : 1, + sticky: window.is_on_all_workspaces() }; console.log('[WindowPositioner] Returning window data:', JSON.stringify(windowData)); @@ -377,7 +378,10 @@ export default class WindowPositionerExtension { // Private helper method to move/resize a window, optionally to a specific workspace (1-based) _moveWindow(window, x, y, width, height, workspace = 0) { try { - if (workspace > 0) { + if (workspace === 0) { + window.stick(); + } else if (workspace > 0) { + window.unstick(); const workspaceManager = global.workspace_manager; const targetWorkspace = workspaceManager.get_workspace_by_index(workspace - 1); if (targetWorkspace) { diff --git a/position b/position index 4d67120..4b4a467 100755 --- a/position +++ b/position @@ -28,14 +28,16 @@ save_config() { local name="$1" local window_data="$2" - local x y width height wmclass title workspace + local x y width height wmclass title workspace sticky x=$(echo "$window_data" | jq -r .x) y=$(echo "$window_data" | jq -r .y) width=$(echo "$window_data" | jq -r .width) height=$(echo "$window_data" | jq -r .height) wmclass=$(echo "$window_data" | jq -r .wmClass) title=$(echo "$window_data" | jq -r .title) - workspace=$(echo "$window_data" | jq -r '.workspace // 0') + workspace=$(echo "$window_data" | jq -r '.workspace // 1') + sticky=$(echo "$window_data" | jq -r '.sticky // false') + [ "$sticky" = "true" ] && workspace=0 # Extract title pattern - preserve dashes and underscores local title_pattern @@ -60,9 +62,15 @@ save_config() { fi # Workspace (auto-captured, allow override) - read -r -p "Workspace [$workspace] (0 = any workspace): " new_workspace + if [ "$workspace" = "0" ]; then + read -r -p "Workspace [0 - sticky/all workspaces] (Enter to keep, number to pin to workspace): " new_workspace + else + read -r -p "Workspace [$workspace] (0=sticky, Enter to skip, number to pin): " new_workspace + fi if [ -n "$new_workspace" ]; then workspace="$new_workspace" + elif [ "$sticky" != "true" ]; then + workspace="" fi # App group and profile metadata @@ -94,7 +102,7 @@ save_config() { if [ -n "$title_pattern" ]; then echo "title_pattern = \"$title_pattern\"" fi - if [ "$workspace" -gt 0 ] 2>/dev/null; then + if [[ "$workspace" =~ ^[0-9]+$ ]]; then echo "workspace = $workspace" fi if [ -n "$app_group" ]; then @@ -199,7 +207,7 @@ capture_window() { echo "$clean_data" | jq -r '"Class: " + .wmClass' echo "$clean_data" | jq -r '"Position: " + (.x|tostring) + "," + (.y|tostring)' echo "$clean_data" | jq -r '"Size: " + (.width|tostring) + "x" + (.height|tostring)' - echo "$clean_data" | jq -r '"Workspace: " + ((.workspace // 1) | tostring)' + echo "$clean_data" | jq -r 'if .sticky then "Workspace: all (sticky)" else "Workspace: " + ((.workspace // 1) | tostring) end' echo read -r -p "Enter a name for this preset: " name @@ -428,7 +436,7 @@ edit_config() { read -r -p "Height [$current_height]: " new_height read -r -p "WM Class [$current_wmclass]: " new_wmclass read -r -p "Title Pattern [$current_title_pattern]: " new_title_pattern - read -r -p "Workspace [$current_workspace] (0 = any): " new_workspace + read -r -p "Workspace [$current_workspace] (0=sticky, blank=any): " new_workspace read -r -p "App group [$current_app]: " new_app read -r -p "Profile [$current_profile]: " new_profile @@ -472,7 +480,7 @@ edit_config() { if [ -n "$new_title_pattern" ]; then echo "title_pattern = \"$new_title_pattern\"" fi - if [ "$new_workspace" -gt 0 ] 2>/dev/null; then + if [[ "$new_workspace" =~ ^[0-9]+$ ]]; then echo "workspace = $new_workspace" fi if [ -n "$new_app" ]; then @@ -598,7 +606,7 @@ list_configs() { in_target && /^height = / { printf "x%s\n", substr($0,10) } in_target && /^wm_class = / { v=substr($0,12); gsub(/^"|"$/,"",v); printf " WM Class: %s\n", v } in_target && /^title_pattern = / { v=substr($0,17); gsub(/^"|"$/,"",v); printf " Title Pattern: %s\n", v } - in_target && /^workspace = / { printf " Workspace: %s\n", substr($0,13) } + in_target && /^workspace = / { ws=substr($0,13); printf " Workspace: %s\n", (ws=="0" ? "all (sticky)" : ws) } in_target && /^app = / { v=substr($0,7); gsub(/^"|"$/,"",v); printf " App: %s\n", v } in_target && /^profile = / { v=substr($0,11); gsub(/^"|"$/,"",v); printf " Profile: %s\n", v } ' "$CONFIG_FILE" @@ -616,7 +624,7 @@ list_configs() { /^height = / { printf "x%s\n", substr($0,10) } /^wm_class = / { v=substr($0,12); gsub(/^"|"$/,"",v); printf " WM Class: %s\n", v } /^title_pattern = / { v=substr($0,17); gsub(/^"|"$/,"",v); printf " Title Pattern: %s\n", v } - /^workspace = / { printf " Workspace: %s\n", substr($0,13) } + /^workspace = / { ws=substr($0,13); printf " Workspace: %s\n", (ws=="0" ? "all (sticky)" : ws) } /^app = / { v=substr($0,7); gsub(/^"|"$/,"",v); printf " App: %s\n", v } /^profile = / { v=substr($0,11); gsub(/^"|"$/,"",v); printf " Profile: %s\n", v } ' "$CONFIG_FILE" From ae6d5bf8b10c7b8c8b4b0907b0b64fd8b22d853e Mon Sep 17 00:00:00 2001 From: Edward Zwart Date: Wed, 20 May 2026 10:32:24 -0700 Subject: [PATCH 07/10] Add examples to app group and profile prompts in edit --- position | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/position b/position index 4b4a467..c52b1ac 100755 --- a/position +++ b/position @@ -437,8 +437,8 @@ edit_config() { read -r -p "WM Class [$current_wmclass]: " new_wmclass read -r -p "Title Pattern [$current_title_pattern]: " new_title_pattern read -r -p "Workspace [$current_workspace] (0=sticky, blank=any): " new_workspace - read -r -p "App group [$current_app]: " new_app - read -r -p "Profile [$current_profile]: " new_profile + read -r -p "App group [$current_app] (e.g. chrome, terminal): " new_app + read -r -p "Profile [$current_profile] (e.g. work, personal): " new_profile [ -z "$new_name" ] && new_name="$current_name" [ -z "$new_x" ] && new_x="$current_x" From 40ab5a6fe1b53b01c34e6970de520e2b13098262 Mon Sep 17 00:00:00 2001 From: Edward Zwart Date: Wed, 20 May 2026 10:33:22 -0700 Subject: [PATCH 08/10] Improve prompt help text for title pattern, preset name, and edit title pattern --- position | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/position b/position index c52b1ac..101d55d 100755 --- a/position +++ b/position @@ -45,7 +45,7 @@ save_config() { if [ -z "$title_pattern" ] || [ ${#title_pattern} -lt 2 ]; then echo -e "${YELLOW}Window title: $title${NC}" - read -r -p "Enter a title pattern to match (or press Enter to use WM_CLASS only): " user_pattern + read -r -p "Enter a title pattern to match (e.g. 'Work' matches any title containing 'Work', or press Enter to use WM_CLASS only): " user_pattern if [ -n "$user_pattern" ]; then title_pattern="$user_pattern" else @@ -210,7 +210,7 @@ capture_window() { echo "$clean_data" | jq -r 'if .sticky then "Workspace: all (sticky)" else "Workspace: " + ((.workspace // 1) | tostring) end' echo - read -r -p "Enter a name for this preset: " name + read -r -p "Enter a name for this preset (e.g. keepass, chrome-work — becomes the command you run): " name if [ -z "$name" ]; then echo -e "${RED}No name provided. Cancelled.${NC}" @@ -435,7 +435,7 @@ edit_config() { read -r -p "Width [$current_width]: " new_width read -r -p "Height [$current_height]: " new_height read -r -p "WM Class [$current_wmclass]: " new_wmclass - read -r -p "Title Pattern [$current_title_pattern]: " new_title_pattern + read -r -p "Title Pattern [$current_title_pattern] (e.g. 'Work' matches any title containing 'Work', blank = match any title): " new_title_pattern read -r -p "Workspace [$current_workspace] (0=sticky, blank=any): " new_workspace read -r -p "App group [$current_app] (e.g. chrome, terminal): " new_app read -r -p "Profile [$current_profile] (e.g. work, personal): " new_profile From 8208d255d67e0b03968433cd12f3f7bcd5043dda Mon Sep 17 00:00:00 2001 From: Edward Zwart Date: Fri, 12 Jun 2026 10:55:00 -0700 Subject: [PATCH 09/10] Add Gemini AI directives Gemini project configuration file, likely from an earlier experiment. --- GEMINI.md | 71 +++++++++++++++++++++---------------------------------- 1 file changed, 27 insertions(+), 44 deletions(-) diff --git a/GEMINI.md b/GEMINI.md index 8fd1888..0dece2d 100644 --- a/GEMINI.md +++ b/GEMINI.md @@ -1,55 +1,38 @@ -# Project Conventions +# Project Directives -This document outlines the key development conventions for this project to ensure consistency and clarity. +This document contains the primary operating directives for the Gemini AI +assistant on this project. It also serves as a high-level guide for human +contributors. -## Branch Naming Strategy +## Key Project Files -All development work should be done on branches that follow a specific naming convention. The format is `issue/-`. +This section acts as a map for the AI assistant. -- **With an Issue:** `issue/42-login-security` -- **Without an Issue:** `issue/nt-shellcheck-config` +- **`GEMINI.md` (This file):** My core principles and directives. Contains the + "why" behind our workflow and specific instructions for my behavior. +- **`CONTRIBUTING.md`:** The detailed, step-by-step "how-to" guide for human + developers. It contains the specifics of branch naming, local commits, and + PR titles. I will refer to this when I need to remind humans of the + process. +- **`README.md`:** The public-facing project overview. It explains what the + project is and how to install and use it. +- **`DESIGN_RATIONALE.md`:** The meta-document explaining the "why" behind the + project's structure and conventions. -## Local Commit Message Strategy - -All local commits must be prefixed with the relevant issue number or the `NT` identifier. - -- **Format:** `#: ` or `NT: ` -- **Example:** `#42: Add user model` or `NT: Configure linter` - -## Pull Request (PR) Naming Strategy - -PR titles are optimized for scannability and should be short and direct. Avoid words that don't provide any meaningful additional context. -For example, 'improve', 'update', 'refactor'. Simple noun phrases are often enough clarity to distinguish one PR from the others. - -- **With an Issue:** `#42: Login security` -- **Without an Issue:** `NT: Shellcheck configuration` - -## Final Commit Message Strategy - -We always use the "Squash and Merge" option on GitHub. This ensures that main is always buildable, runnable and releasable: a core feature of trunk-based development. -During squash and merge is where we create high-quality, permanent commit messages. The merger has two options: - -### 1. Manual Edit (for simple PRs) - -For straightforward changes, the merger can manually edit the commit message in the GitHub UI. The goal is to transform the PR title into a descriptive commit subject, often simply by adding a verb. - -- **PR Title:** `#42: Login security` -- **Final Commit Subject:** `#42: Improve login security` +## Development Philosophy -### 2. AI-Assisted Generation (for complex PRs) +Our central philosophy is **Trunk-Based Development (TBD)**. The `main` branch +must always be stable and releasable. My primary goal is to help enforce the +conventions that support this philosophy. -For more complex changes, the merger can ask Gemini to generate the complete, formatted squash commit message. +## AI-Assisted Generation +When asked to generate a squash commit message, I will provide a complete, +formatted message including a descriptive subject and a detailed body. - **Prompt:** `Generate the squash commit message for PR #.` -- **Action:** Gemini will provide the full subject and body. The merger will then copy this text and paste it into the squash-and-merge dialog in the GitHub UI. -**Example AI-Generated Output:** -``` -#42: Improve login security - -Adds rate limiting to the authentication endpoint to prevent brute-force attacks. The configuration is stored in the new `security.yml` file. -``` - -## Development Philosophy +## Formatting and Style -This project is a live sandbox for experimenting with and documenting modern development practices, including AI tooling, workflow automation, and version control strategies. The conventions in this file are a living document. +All Markdown files (`.md`) should be formatted to have a line length of 80 +characters. This is a strong guideline that can be broken for content like +tables or long URLs. \ No newline at end of file From b4c1b5537fd0dfd9c1e3aa690c3c8772244edf4b Mon Sep 17 00:00:00 2001 From: Edward Zwart Date: Fri, 12 Jun 2026 10:55:05 -0700 Subject: [PATCH 10/10] Gate extension logging behind DEBUG flag, keep loaded during lock screen All verbose console.log calls are now no-ops unless DEBUG=true at the top of extension.js. Eliminates ~14k journal lines per boot and the per-failed- match window dump. console.error calls are unchanged. Also adds session-modes: unlock-dialog to metadata.json so the extension stays loaded across screensaver activate/deactivate, avoiding the repeated disable/enable GC cycles. --- extension.js | 60 +++++++++++++++++++++++++++------------------------ metadata.json | 1 + 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/extension.js b/extension.js index e2e4c10..dce2e22 100644 --- a/extension.js +++ b/extension.js @@ -3,6 +3,9 @@ import Gio from 'gi://Gio'; import * as Main from 'resource:///org/gnome/shell/ui/main.js'; +const DEBUG = false; +const log = (...args) => { if (DEBUG) console.log(...args); }; + const DBUS_INTERFACE_XML = ` @@ -70,13 +73,13 @@ export default class WindowPositionerExtension { enable() { try { - console.log('[WindowPositioner] Enabling extension...'); - + log('[WindowPositioner] Enabling extension...'); + // Create D-Bus exported object this._dbus = Gio.DBusExportedObject.wrapJSObject(DBUS_INTERFACE_XML, this); this._dbus.export(Gio.DBus.session, '/org/gnome/Shell/WindowPositioner'); - - console.log('[WindowPositioner] Extension enabled successfully - D-Bus interface exported'); + + log('[WindowPositioner] Extension enabled successfully - D-Bus interface exported'); } catch (error) { console.error('[WindowPositioner] Failed to enable extension:', error); throw error; @@ -85,14 +88,14 @@ export default class WindowPositionerExtension { disable() { try { - console.log('[WindowPositioner] Disabling extension...'); - + log('[WindowPositioner] Disabling extension...'); + if (this._dbus) { this._dbus.unexport(); this._dbus = null; } - - console.log('[WindowPositioner] Extension disabled successfully'); + + log('[WindowPositioner] Extension disabled successfully'); } catch (error) { console.error('[WindowPositioner] Failed to disable extension:', error); } @@ -101,7 +104,7 @@ export default class WindowPositionerExtension { // Find window by title (partial case-insensitive match) PositionWindow(windowTitle, x, y, width, height) { try { - console.log(`[WindowPositioner] PositionWindow: "${windowTitle}" to ${x},${y} ${width}x${height}`); + log(`[WindowPositioner] PositionWindow: "${windowTitle}" to ${x},${y} ${width}x${height}`); const windows = global.get_window_actors(); let targetWindow = null; @@ -117,7 +120,7 @@ export default class WindowPositionerExtension { } if (!targetWindow) { - console.log(`[WindowPositioner] Window with title containing "${windowTitle}" not found`); + log(`[WindowPositioner] Window with title containing "${windowTitle}" not found`); return false; } @@ -131,7 +134,7 @@ export default class WindowPositionerExtension { // Find window by WM_CLASS PositionWindowByClass(wmClass, x, y, width, height) { try { - console.log(`[WindowPositioner] PositionWindowByClass: "${wmClass}" to ${x},${y} ${width}x${height}`); + log(`[WindowPositioner] PositionWindowByClass: "${wmClass}" to ${x},${y} ${width}x${height}`); const windows = global.get_window_actors(); let targetWindow = null; @@ -147,7 +150,7 @@ export default class WindowPositionerExtension { } if (!targetWindow) { - console.log(`[WindowPositioner] Window with WM_CLASS "${wmClass}" not found`); + log(`[WindowPositioner] Window with WM_CLASS "${wmClass}" not found`); this._debugAvailableWindows(); return false; } @@ -162,7 +165,7 @@ export default class WindowPositionerExtension { // Find window by WM_CLASS and title pattern PositionWindowByClassAndTitle(wmClass, titlePattern, x, y, width, height) { try { - console.log(`[WindowPositioner] PositionWindowByClassAndTitle: "${wmClass}" + "${titlePattern}" to ${x},${y} ${width}x${height}`); + log(`[WindowPositioner] PositionWindowByClassAndTitle: "${wmClass}" + "${titlePattern}" to ${x},${y} ${width}x${height}`); const windows = global.get_window_actors(); let targetWindow = null; @@ -180,7 +183,7 @@ export default class WindowPositionerExtension { } if (!targetWindow) { - console.log(`[WindowPositioner] Window with WM_CLASS "${wmClass}" and title containing "${titlePattern}" not found`); + log(`[WindowPositioner] Window with WM_CLASS "${wmClass}" and title containing "${titlePattern}" not found`); this._debugAvailableWindows(); return false; } @@ -195,7 +198,7 @@ export default class WindowPositionerExtension { // Get information about the currently active window GetActiveWindowInfo() { try { - console.log('[WindowPositioner] GetActiveWindowInfo called'); + log('[WindowPositioner] GetActiveWindowInfo called'); // Try multiple methods to get the focused window let window = global.display.get_focus_window(); @@ -214,7 +217,7 @@ export default class WindowPositionerExtension { if (!window) { const errorData = { error: "No active window found" }; - console.log('[WindowPositioner] No active window found'); + log('[WindowPositioner] No active window found'); return JSON.stringify(errorData); } @@ -233,7 +236,7 @@ export default class WindowPositionerExtension { sticky: window.is_on_all_workspaces() }; - console.log('[WindowPositioner] Returning window data:', JSON.stringify(windowData)); + log('[WindowPositioner] Returning window data:', JSON.stringify(windowData)); return JSON.stringify(windowData); } catch (error) { console.error('[WindowPositioner] Error in GetActiveWindowInfo:', error); @@ -244,7 +247,7 @@ export default class WindowPositionerExtension { // Get monitor layout information GetMonitorInfo() { try { - console.log('[WindowPositioner] GetMonitorInfo called'); + log('[WindowPositioner] GetMonitorInfo called'); const monitors = Main.layoutManager.monitors; const monitorData = []; @@ -261,7 +264,7 @@ export default class WindowPositionerExtension { }); const result = JSON.stringify(monitorData); - console.log('[WindowPositioner] Returning monitor data:', result); + log('[WindowPositioner] Returning monitor data:', result); return result; } catch (error) { console.error('[WindowPositioner] Error in GetMonitorInfo:', error); @@ -272,7 +275,7 @@ export default class WindowPositionerExtension { // Get information about a specific window by title GetWindowInfo(windowTitle) { try { - console.log(`[WindowPositioner] GetWindowInfo: "${windowTitle}"`); + log(`[WindowPositioner] GetWindowInfo: "${windowTitle}"`); const windows = global.get_window_actors(); let targetWindow = null; @@ -314,7 +317,7 @@ export default class WindowPositionerExtension { // Find window by WM_CLASS and move to workspace before positioning PositionWindowByClassOnWorkspace(wmClass, workspace, x, y, width, height) { try { - console.log(`[WindowPositioner] PositionWindowByClassOnWorkspace: "${wmClass}" ws=${workspace} to ${x},${y} ${width}x${height}`); + log(`[WindowPositioner] PositionWindowByClassOnWorkspace: "${wmClass}" ws=${workspace} to ${x},${y} ${width}x${height}`); const windows = global.get_window_actors(); let targetWindow = null; @@ -330,7 +333,7 @@ export default class WindowPositionerExtension { } if (!targetWindow) { - console.log(`[WindowPositioner] Window with WM_CLASS "${wmClass}" not found`); + log(`[WindowPositioner] Window with WM_CLASS "${wmClass}" not found`); this._debugAvailableWindows(); return false; } @@ -345,7 +348,7 @@ export default class WindowPositionerExtension { // Find window by WM_CLASS and title, move to workspace before positioning PositionWindowByClassAndTitleOnWorkspace(wmClass, titlePattern, workspace, x, y, width, height) { try { - console.log(`[WindowPositioner] PositionWindowByClassAndTitleOnWorkspace: "${wmClass}" + "${titlePattern}" ws=${workspace} to ${x},${y} ${width}x${height}`); + log(`[WindowPositioner] PositionWindowByClassAndTitleOnWorkspace: "${wmClass}" + "${titlePattern}" ws=${workspace} to ${x},${y} ${width}x${height}`); const windows = global.get_window_actors(); let targetWindow = null; @@ -363,7 +366,7 @@ export default class WindowPositionerExtension { } if (!targetWindow) { - console.log(`[WindowPositioner] Window with WM_CLASS "${wmClass}" and title containing "${titlePattern}" not found`); + log(`[WindowPositioner] Window with WM_CLASS "${wmClass}" and title containing "${titlePattern}" not found`); this._debugAvailableWindows(); return false; } @@ -397,7 +400,7 @@ export default class WindowPositionerExtension { const title = window.get_title(); const wmClass = window.get_wm_class(); - console.log(`[WindowPositioner] Successfully positioned "${title}" (${wmClass}) to ${x},${y} ${width}x${height}`); + log(`[WindowPositioner] Successfully positioned "${title}" (${wmClass}) to ${x},${y} ${width}x${height}`); return true; } catch (error) { @@ -408,16 +411,17 @@ export default class WindowPositionerExtension { // Debug helper to list available windows _debugAvailableWindows() { + if (!DEBUG) return; try { - console.log('[WindowPositioner] Available windows:'); + log('[WindowPositioner] Available windows:'); const windows = global.get_window_actors(); - + windows.forEach((windowActor, index) => { const window = windowActor.get_meta_window(); if (window.get_window_type() === 0) { // Normal windows only const title = window.get_title() || "No title"; const wmClass = window.get_wm_class() || "No class"; - console.log(`[WindowPositioner] ${index}: "${wmClass}" - "${title}"`); + log(`[WindowPositioner] ${index}: "${wmClass}" - "${title}"`); } }); } catch (error) { diff --git a/metadata.json b/metadata.json index a2d3387..70f72dc 100644 --- a/metadata.json +++ b/metadata.json @@ -3,5 +3,6 @@ "description": "Enhanced window positioning with learning capabilities - position windows by WM_CLASS and capture configurations", "uuid": "window-positioner@example.com", "shell-version": ["46"], + "session-modes": ["user", "unlock-dialog"], "version": 4 } \ No newline at end of file