leukipp / cortile

Linux auto tiling manager with hot corner support for Openbox, Fluxbox, IceWM, Xfwm, KWin, Marco, Muffin, Mutter and other EWMH compliant window managers using the X11 window system. Therefore, this project provides dynamic tiling for XFCE, LXDE, LXQt, KDE and GNOME (Mate, Deepin, Cinnamon, Budgie) based desktop environments.
https://github.com/leukipp/cortile-addons
MIT License
589 stars 19 forks source link

[question] socket communication commands to enable/disable cortile #43

Closed ahmeteid7 closed 8 months ago

ahmeteid7 commented 8 months ago

sorry, i wish if i can know what disable does in cortile as command , i mean it's not kill, it's stop?

leukipp commented 8 months ago

Disable tiling as described here: https://github.com/leukipp/cortile/blob/e9328e36bc575224d331e5baa3c6bae9c874377d/config.toml#L118C5-L118C5

ahmeteid7 commented 8 months ago
# Check if Cortile is running
if pgrep -f "/home/eid/go/bin/cortile" > /dev/null; then #that consider disable and exit as not running state, i wish if i can check the disable state separately 
    # The application is running, so let's kill it
    echo '{"Action":"layout_fullscreen"}' | nc -U /tmp/cortile.sock.in
    sleep 1
    pkill -f "/home/eid/go/bin/cortile"
 else
    # The application is not running, so let's start it
    /home/eid/go/bin/cortile &
leukipp commented 8 months ago

If you are talking about socket communication commands (#41) you can use

echo '{"Action":"exit"}' | nc -U /tmp/cortile.sock.in

to gracefully stop cortile (the process is not running any more). When using

echo '{"Action":"disable"}' | nc -U /tmp/cortile.sock.in

the process still runs in the background and is listening for an enable command (e.g. via keyboard shortcut).

You can use any command available in the config.toml, e.g. also

echo '{"Action":"toggle"}' | nc -U /tmp/cortile.sock.in

As described in the README https://github.com/leukipp/cortile?tab=readme-ov-file#incoming-commands-and-requests the current state can also be requested. Here you would need two processes (two terminal windows) running. One is for listening and the other is for sending. Using the scripts you should be able to do this:

# terminal 1 (input)
./listen.sh -s /tmp/cortile.sock
# terminal 2 (input)
./send.sh -s /tmp/cortile.sock -m '{"State":"workspaces"}'
# terminal 1 (output)
Received 'workspaces' with tiling 'enabled = true' on 'desktop = 0' and 'screen = 1' with 'layout = 2'

The listening terminal 1 will also output all the internal commands executed by cortile.

ahmeteid7 commented 8 months ago

what i mean is to check disable and enable state by script, based on that i can do things, like new toggle(that toggle bw disable+fullscreen and enable+right layout) , or do things like exit with fullscreen to avoid the affect of tiling after exit etc. to try to do check disable or enable state :

#!/bin/bash

FLAG_FILE="/tmp/cortile_flag"

# Create the file with initial state if it doesn't exist
[ -e "$FLAG_FILE" ] || echo "disable" > "$FLAG_FILE"

# Read the current state from the file
flag=$(cat "$FLAG_FILE")

if [ "$flag" == "enable" ]; then
    # Disable
    sleep 1
    echo '{"Action":"layout_fullscreen"}' | nc -U /tmp/cortile.sock.in
    sleep 1
    echo '{"Action":"disable"}' | nc -U /tmp/cortile.sock.in
else
    # Enable
    echo '{"Action":"enable"}' | nc -U /tmp/cortile.sock.in
    sleep 1
    echo '{"Action":"layout_vertical_right"}' | nc -U /tmp/cortile.sock.in
fi

# Toggle the state by updating the flag file (moved to the end)
[ "$flag" == "enable" ] && echo "disable" > "$FLAG_FILE" || echo "enable" > "$FLAG_FILE"

that script worked with me, but i think may be easy check with socket communication, i'll try to understand it

leukipp commented 8 months ago

You could use the listen.sh script as a template and write the flag file somewhere starting here.

Your solution will work if you only use the script to execute commands (e.g. not using cortile key-bindings at all). Also keep in mind that the enable state of cortile is per workspace and per screen. So depending on you setup you would need n = num_workspaces * num_screens numbers of flag files.

There is another hacky way to execute scripts. Any command not recognized by cortile will be executed as external command. Therefore, something like this will also work:

# config.toml

"/tmp/my_script.sh enable" = "Control-Shift-A"
"/tmp/my_script.sh disable" = "Control-Shift-B"
# my_script.sh

if [ "$1" == "disable" ]; then
    # Disable
    echo '{"Action":"layout_fullscreen"}' | nc -U /tmp/cortile.sock.in
    echo '{"Action":"disable"}' | nc -U /tmp/cortile.sock.in
else
    # Enable
    echo '{"Action":"enable"}' | nc -U /tmp/cortile.sock.in
    echo '{"Action":"layout_vertical_right"}' | nc -U /tmp/cortile.sock.in
fi
ahmeteid7 commented 8 months ago

i tried the hacky way, and make it toggle based on flag(create empty file and delete it)

#!/bin/bash

FLAG_FILE="/tmp/cortile_flag"

# Toggle Cortile state
if [ -e "$FLAG_FILE" ]; then
    echo '{"Action":"layout_fullscreen"}' | nc -U /tmp/cortile.sock.in
    sleep 1
    echo '{"Action":"disable"}' | nc -U /tmp/cortile.sock.in
    rm "$FLAG_FILE"
else
    echo '{"Action":"enable"}' | nc -U /tmp/cortile.sock.in
    echo '{"Action":"layout_vertical_right"}' | nc -U /tmp/cortile.sock.in
    touch "$FLAG_FILE"
fi

config.toml "/home/eid/Desktop/toggle.sh toggle"="Control-Shift-KP_0"