Window rule on a sortcut

Hello,

does anyone know, if there is a way to create a general window rule wich could be applied to any window in focus by linking it to a keyboard-shortcut?

For example:
When I open a file-manager, that is placed in the middle of the screen and has maybe a size of 500x500.
Then I would like to have a shortcut to place it in position 40,32 with a size of 1.542x1.048.
And I would like to be able to use this on any window in focus, not just one specific.

Any idea?

On X you could write a little xdotool script for the active window and move it to position with a given size I guess.
Maybe something like:

#!/bin/bash
xdotool getactivewindow windowmove 40 32 windowsize 1542x1048

ā€¦and asign a shortcut to it.

Iā€™m on wayland. But thanks for the idea.

I hoped there maybe is a way to link a window rule to a shortcut inside the kde settings.

But if anyone knows a way to do this via a script on wayland Iā€™ll try that out.

Thenā€¦ydotool I guess. Iā€™m not sure how you can ( if itā€™s even possible) to add that as a windowrule for an active window. I mean, you can add the position , size and shortcut to all. But to get is a the active window onlyā€¦that I donā€™t know.

I searched for xdotool in my repository and was suggested kdotool

kdotool.x86_64 : Xdotool-like tool to manipulate windows on KDE Wayland

And I could use your xdotool-code with it, and it works perfectly :slight_smile: Thanks!

Maybe ydotool would have done the same, and it also was suggested on the github-page of kdotool for additional funtionality. But for me kdotool is fine.

I made the script like you suggested, put it into my .local/bin and assigned a key-shortcut to it.

Now I can maximize any window on my desktop, without hiding my conky on the right :slight_smile:

1 Like

for anyone curious, ydotoold does not run on kubuntu 24.10

searching the error it gives when running ydotool

ydotool: notice: ydotoold backend unavailable

the advice is rebuild from source to get the latest version.

Hey fabio

I have many conkies to show specific things and run them in their own window. They can be placed wherever is needed.

I also have keep-above and keep-below buttons on all titlebars. Easy to use.

Vektor

Hi vektor,

I have just this one conky. It is the same one I use from when I started using it, about 14 years ago. And it always has the same space.

And now with KDE (I used Unity and Gnome since 2022) I have placed a plasmoid under it for taking notes and above my conky are two ā€œbuttonsā€ (ā€˜run commandā€™ plasmoids), that zoom in and out by clicking it.
So, this left space is always covered. So I use all applications only to this space (for example my browser is never fully maximized until I watch a video in fullscreen).

And now, with the kdotool-script I donā€™t even need to drag the size of the windows to the right space, in case I want to. I almost never needed to do this, because the most windows I use are still smaller, and the browser did open in the right place. But itā€™s good to have.

By the way, it could be done even easier, by adding just the command in the shortcut settings of kde. The script in ./local/bin or elsewhere is not needed.

Yes, I know.A script as such is not really needed, no. Not in this case. More elaborate xdotool/kdotool stuff does. For example, I have a script which minimizes all windows except the active one and places it centered on the screen. A bit like the shake function. You canā€™t put that thing in the shortcut section. But in this case itā€™s just a oneliner soā€¦

Right. And interesting :slight_smile:

In realizing that I donā€™t need a real script for this simple commands solved another problem that I had with kscreen-doctor.

When I switched to wayland I had some issues to switch between monitors and didnā€™t know how to solve it. The only thing that fairly worked was to write the commands into a script and start them as a application. I donā€™t know why, but using regular commands either didnā€™t work or I didnā€™t set them up right.
But with the monitor-switch as applications I sometimes had trouble with one of the two monitors. Now, that I run the commands as regular commands there are no problems anymore.

And regarding x11, I wouldnā€™t have switched to wayland in the first place, but one day a nvidia update somehow broke exactly this ability, to switch monitors with xrandr.