cagebreak icon indicating copy to clipboard operation
cagebreak copied to clipboard

Opening new window into empty space

Open mankeli opened this issue 2 years ago • 12 comments

Is it possible to open new window into already empty tile? It seems it currently always opens in the currently selected tile.

mankeli avatar Apr 10 '23 15:04 mankeli

Hi mankeli

What exactly do you mean? Would you like new windows to automatically open in an empty tile? What should happen if all tiles are already full?

Cheers project-repo

project-repo avatar Apr 11 '23 16:04 project-repo

My usecase is an emulator window and it's debugger in terminal.

With a stacking window manager, I launch the emulator from terminal window. The emulator's window opens somewhere on screen, and when i break to debugger I can just alt+tab to terminal window. Quit the emulator and repeat.

With cagebreak, the emulation window opens into same tile as console, then when I break to debugger, I need to split the tile which then puts emulator and terminal window next to each other. Then I can switch to the terminal tile and do my stuff there. If I now quit the emulator, there's an empty tile and need to use "only" command to remove the split. It's just a bunch of unnecessary keypresses.

Probably this could be solved by just having some kind of mechanism to select a tile where next window will be opened. Is it possible?

mankeli avatar Apr 11 '23 21:04 mankeli

I see - thanks for the clarification. Currently, there is no method in cagebreak to natively achieve such behaviour. You could try to use the socket to achieve what you are looking for.

I am thinking of a cagebreak keybinding which would run a skript doing the following:

  • listen on the socket for a "new window" event.
  • split screen.
  • listen on the cagebreak socket for a "close window" event.
  • send the "only" command to the socket.

Depending on how complex you want to make it you could also check that the "new window" and "close window" events come from the correct workspace, tile, pid etc. to make the workflow more robust.

Does that sound like something that would work for you? What do you think?

cheers project-repo

project-repo avatar Apr 12 '23 20:04 project-repo

Hi mankeli

Since this issue has not seen any activity for quite some time and since it does not concern a bug in Cagebreak, we are closing it for now. Feel free to reopen if you have any more information.

cheers project-repo

project-repo avatar Sep 07 '23 17:09 project-repo

Hi! Sorry for fading out last year, my laptop running this experimental setup with Cagebreak got smashed to ice and it took me a while to get a new setup!

So a bit refined idea: I think semantically tagging slots would be a nice feature. To kind of build workspaces. So if you open programs, they would go to specific slots automatically.

I wonder if you could provide a scripting example to send new windows with matching names to specific slots?

Also a bit outlandish idea maybe: While I've been configuring this thing, I've been thinking how awesome it would be to have lua script interpreter integrated in this, but maybe it could be done with just exec and the socket interface?

mankeli avatar May 02 '24 20:05 mankeli

@project-repo sorry I don't know if I have the power to re-open threads :thinking:

mankeli avatar May 03 '24 06:05 mankeli

Hi mankeli

We are currently discussing this internally but find the idea interesting.

We will reopen this for now.

cheers project-repo

project-repo avatar May 04 '24 12:05 project-repo

Hi mankeli

We considered your proposal and came up with a tentative implementation idea.

We would provide a command to move a view to a specific workspace.

syntax:

moveviewtoworkspace <view-id> <output> <workspace>

Using this command, you can write a script which listens for events indicating that a new view has been created and executes a moveviewtoworkspace command based on the title string and pid.

Because we expose almost everything over the socket as json, we don't feel like a native lua interpreter is needed. You are welcome to use lua, or any other language for that matter, to interact with the socket though.

cheers project-repo

project-repo avatar May 04 '24 20:05 project-repo

Does an empty workspace have 1 view, and once-splitted workspace has 2 views etc? With my proposal I meant that I'd like to be able to identify views and send windows into specific views within a workspace.

mankeli avatar May 05 '24 08:05 mankeli

Hi mankeli

Ah I see. No, the correct terminology is that a fullscreen workspace has 1 tile which can have a view (window) displayed within it. What you are planning to do requires a different command which we are also planning on implementing: moveviewtowtile <view-id> <tile-id> The procedure is then as described in the previous post. Does that make sense?

Cheers project-repo

project-repo avatar May 06 '24 06:05 project-repo

Ah, gotcha. Yes, I think that could enable automatic creation of those window (or view) ensembles I was thinking.

mankeli avatar May 06 '24 18:05 mankeli

Because we expose almost everything over the socket as json, we don't feel like a native lua interpreter is needed. You are welcome to use lua, or any other language for that matter, to interact with the socket though.

At the risk of being slightly off-topic and annoying, I wanted to mention something I've been working on for my vehicle mounted touchscreen infotainment system, which is based mainly on Cagebreak and mpv. I wanted to simplify (and eliminate) the touchscreen gesture application I was using and realized that in addition to lua scripts, mpv supports c plugins so I wrote one based on libinput that works well for my needs.

Once I did that, I wrote another c plugin for interacting with the Cagebreak socket. Previously I'd done this with lua in mpv but moving the socket interaction to c made more sense to me. Since mpv provides an internal function for message passing between scripts (and c plugins), it's trivial to pass socket activity to a lua script and vice versa.

As I mentioned in another issue here, mpv also provides some utility functions for working with json, so there's no need (that I've found so far) for using jq or other solution for that.

If you use mpv in this role, you can start it via your Cagebreak config and pass multiple arguments to turn off features, like:

exec mpv --idle --load-scripts=no --video=no --audio=no --sub-ass=no --osc=no --config=no --load-osd-console=no --load-stats-overlay=no --ytdl=no --input-terminal=no --load-auto-profiles=no --script=$HOME/.config/cagebreak/cg-ipcc.so --script=$HOME/.config/cagebreak/cg-ipcl.lua --log-file=$HOME/mpv.log

This may be kind of a silly mis-use of mpv, but if you already have it installed, it might be worth considering.

sodface avatar Jun 21 '24 00:06 sodface

Hi, All features needed to make this possible are now implemented. The following script is a POC of how one might do something similar to what you are asking for. Please let us know if you have further questions. Cheers, project-repo

#!/bin/bash
named_pipe_send="$(mktemp -u)"
named_pipe_recv="$(mktemp -u)"
mkfifo "${named_pipe_send}"
mkfifo "${named_pipe_recv}"
nc -U "${CAGEBREAK_SOCKET}" < "${named_pipe_send}" > "${named_pipe_recv}"&
# The file descriptor 3 is set up to send commands to cagebreak and file
# descriptor 4 can be used to read events. Notice that events will pile up in
# file descriptor 4, so it is a good idea to continuously read from it or to
# clear it before starting a new transaction.
exec 3>"${named_pipe_send}"
exec 4<"${named_pipe_recv}"
# When the script exits, the os will clean up the pipe
rm "${named_pipe_recv}"
rm "${named_pipe_send}"

echo "dump" >&3
moving="true"
while IFS= read -r -d $'\0' event
do
	# Remove the cg-ipc header
	event="${event:6}"
	if [[ "$(echo "${event}" | jq ".event_name")" = "\"view_map\"" ]] && [[ "${moving}" = "true" ]]
	then
		view_id="$(echo "${event}"|jq ".view_id")"
		echo "vsplit" >&3
		moving=true
	elif [[ "$(echo "${event}" | jq ".event_name")" = "\"split\"" ]] && [[ "${moving}" = "false" ]]
	then
		moving=false
		tile_id="$(echo "${event}"|jq ".new_tile_id")"
		echo "moveviewtotile ${view_id} ${tile_id}" >&3
	fi
done <&4

project-repo avatar May 31 '25 14:05 project-repo