Xfce Forum

Sub domains
 

You are not logged in.

#1 2021-11-27 22:29:38

Tio
Member
Registered: 2021-09-26
Posts: 92

Open only specific window under mouse coursor

Is there a way to create a bash script or a command line that will only open the X application under the mouse pointer? Can be useful for apps like the app-finder https://gitlab.xfce.org/xfce/xfce4-appfinder - if I add a launcher on the panel and click it, to open it there. But for the rest of the windows to open at the center of the screen.

And is it also possible to force open a window without the top bar?

These are possible as options in XFCE, but I do not know how they can be forced only for specific applications.

Last edited by Tio (2021-11-27 22:33:09)

Offline

#2 2021-11-28 00:36:43

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: Open only specific window under mouse coursor

Tio wrote:

Is there a way to create a bash script or a command line that will only open the X application under the mouse pointer? Can be useful for apps like the app-finder https://gitlab.xfce.org/xfce/xfce4-appfinder - if I add a launcher on the panel and click it, to open it there. But for the rest of the windows to open at the center of the screen.

But if you click on the launcher, the mouse will always be at the launcher.

And is it also possible to force open a window without the top bar?

Devilspie can do this for you. A .ds file like:

(if (is (application_name) "xfce4-appfinder")
        (begin
		(skip_tasklist)
		(skip_pager)
		(undecorate)
		(above)
                (geometry "626x495+38+23")

	)
)

...will open the xfce4-appfinder undecorated, above other windows, at a specific position on the screen, and no entries in the tasklist (window buttons) or pager (workspaces).


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2021-11-29 11:01:34

Tio
Member
Registered: 2021-09-26
Posts: 92

Re: Open only specific window under mouse coursor

Thanks so much! Luckily the appfinder developer just added an option to remove the window decorations so it fixes this problem I mentioned above. As for opening a window under the mouse cursor it is true, if you click a launcher then it opens near to it. But what I wanted is this: the Super key opens the appfinder in the center of the window, as it should. Alongside all other windows. But to then also create a launcher that, via a script, can launch the same appfinder under the mouse pointer. This way, something like appfinder can act both as a menu or an appfinder. You know what I mean?

Offline

#4 2021-11-29 11:21:00

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: Open only specific window under mouse coursor

I saw your bug report and the upcoming merge request. Wouldn't it make sense to just have appfinder open centered all the time?


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#5 2021-11-29 11:23:31

Tio
Member
Registered: 2021-09-26
Posts: 92

Re: Open only specific window under mouse coursor

Yes it makes sense to have it opened to the center. But if it is added as a button on the panel it would be nice to open near where the button is. Else you go with the mouse to the button, click it, then have to move again your attention to the center of the screen. I thought it can be a useful UI improvement. A key opens it in the center, a button can open it close to the button. It is not a huge deal but I wanted to check with you guys and see what you think and if there are any solutions to this. And thanks for always being so friendly and helpful.

Offline

#6 2021-11-29 11:43:09

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: Open only specific window under mouse coursor

Something like this as a launcher command kind of works. It draws then moves the window (you need xdotool installed):

bash -c "xfce4-appfinder & sleep .25s && xdotool getactivewindow windowmove $(xdotool getmouselocation --shell | grep X | awk -F'=' '{print $2}') $(xdotool getmouselocation --shell | grep Y | awk -F'=' '{print $2}')"

If the window doesn't move to the mousepointer, increase the value of the sleep time.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#7 2021-11-29 11:52:32

Tio
Member
Registered: 2021-09-26
Posts: 92

Re: Open only specific window under mouse coursor

Ah we are getting somewhere. Is just that it showcases bellow the pointer and gets partially hidden.

Offline

#8 2021-11-29 12:05:42

Tio
Member
Registered: 2021-09-26
Posts: 92

Re: Open only specific window under mouse coursor

Oh and sometimes I see it does it with whatever window was in focus. Which is weird. Increasing the sleep time fixes it but you can see the delayed window moving from center to the bottom.

Last edited by Tio (2021-11-29 12:09:37)

Offline

#9 2021-11-29 19:53:46

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: Open only specific window under mouse coursor

Tio wrote:

Ah we are getting somewhere. Is just that it showcases bellow the pointer and gets partially hidden.

Here is a script that will launch and re-position xfce4-appfinder within the confines of the screen dimensions. It still suffers from the same issue - the program loads then automatically moves to the new position. It would be helpful if xfce4-appfinder can support "--geometry" parameters to position itself anywhere on the screen.

#!/bin/bash

# get screen dimensions [ $sw $sh ]
eval $(xrandr | grep \* | awk '{print $1}' | awk -F'x' '{printf "sw=%d\nsh=%d",$1, $2}')

# get mouse pointer location [ $X $Y ]
eval $(xdotool getmouselocation --shell | head -2)

# start the app
xfce4-appfinder &

# pause for window to load
sleep .25s

# get appfinder dimensions [ $wx $wy $ww $wh ]
eval $(wmctrl -lG | grep "Application Finder" | awk '{printf "wx=%d\nwy=%d\nww=%d\nwh=%d",$3, $4, $5, $6}')

# get new window x value ensuring it remains on screen
	# if mouse x + window width is greater than screen width, then move new window x to the left to fit
if [ $((X+ww)) -gt $sw ]; then X=$((sw-ww)); fi

# get new window y value ensuring it remains on screen
	# if mouse y + window height is greater than screen height, then move new window y up to fit
if [ $((Y+wh)) -gt $sh ]; then Y=$((sh-wh)); fi

# move the window to the mouse pointer, while fitting on the screen
xdotool getactivewindow windowmove $X $Y

Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#10 2021-11-29 21:52:22

Tio
Member
Registered: 2021-09-26
Posts: 92

Re: Open only specific window under mouse coursor

Thank you! However this is the result https://videos.trom.tf/w/ns7UuXphszWNweVafEsyP1 . I am also wondering if you click the same launcher it won't close, of course, it will try to reopen it. Maybe I am stretching this more than this app is meant to be. I was thinking, since this appfinder has categories, is fast, and works quite well, to be used as the main menu too, on a distro. But for that to work properly I think it has to have a proper plugin/button, that can open it close to where the button is on the panel.

Offline

#11 2021-11-29 23:08:02

Misko_2083
Member
Registered: 2015-10-13
Posts: 191
Website

Re: Open only specific window under mouse coursor

Place this at the top just under #/bin/bash

# If the window is registered with X: close it and exit script
if xdotool windowunmap $(xdotool search --onlyvisible --class "xfce4-appfinder") >/dev/null 2>&1; then
   exit
fi

Also the pause can be longer sometimes until the window is registered with X.
So it would be better top wait until the window becomes visible.

# start the app and pause for window to load
xfce4-appfinder & until xdotool search --onlyvisible --class "xfce4-appfinder" >/dev/null 2>&1; do sleep .1; done

Sleep time can be shorter but more CPU load.

The proper plugin would be similar to the whisker menu.
Well it takes some calculation where to position the window next to the panel button, on the correct screen and inside work area.

xprop -root _NET_WORKAREA

I'm not sure how will that work when xfce switch to wayland.

Last edited by Misko_2083 (2021-11-29 23:46:27)


Do you want to exit the Circus?
https://www.youtube.com/watch?v=ZJwQicZHp_c

Offline

#12 2021-11-30 00:08:13

Tio
Member
Registered: 2021-09-26
Posts: 92

Re: Open only specific window under mouse coursor

Hmmm I get the same behavior honestly. But I have a question: xfce allows you to select "place window under the mouse cursor" and if that is selected appfinder opens correctly near the launcher for appfinder. But it also does it for all windows, of course...so isn't there a way to use that option in XFCE but only for the appfinder? Wouldn't that make it easier and make more sense?

Offline

#13 2021-11-30 00:17:11

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: Open only specific window under mouse coursor

Thanks @Misko_2083, those are some really good suggestions.

Also, pressing ESC will close the appfinder window.

@Tio, as sanity check, can you post back the results of the following commands:

xrandr | grep \* | awk '{print $1}' | awk -F'x' '{printf "sw=%d\nsh=%d",$1, $2}'
xdotool getmouselocation --shell | head -2

...and with the appfinder window open:

wmctrl -lG | grep "Application Finder" | awk '{printf "wx=%d\nwy=%d\nww=%d\nwh=%d",$3, $4, $5, $6}'

Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#14 2021-11-30 00:18:52

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: Open only specific window under mouse coursor

Tio wrote:

Hmmm I get the same behavior honestly. But I have a question: xfce allows you to select "place window under the mouse cursor" and if that is selected appfinder opens correctly near the launcher for appfinder. But it also does it for all windows, of course...so isn't there a way to use that option in XFCE but only for the appfinder?

Unfortunately, that setting is an all-or-nothing setting.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#15 2021-11-30 00:44:21

Tio
Member
Registered: 2021-09-26
Posts: 92

Re: Open only specific window under mouse coursor

Sure:

xrandr | grep \* | awk '{print $1}' | awk -F'x' '{printf "sw=%d\nsh=%d",$1, $2}'
xdotool getmouselocation --shell | head -2
sw=1920
sh=1080X=860
Y=604

And oh I did not have "wmctrl" in my current VM. Installing it works a lot better with the script you guys made. Here's a demo:
https://videos.trom.tf/w/gESPqx6BG5QAWFj3SkMsGh

It is a  bit laggy tho. Also the bottom part is cut from the appfinder window. Can it be positioned a bit more on top?

Offline

#16 2021-11-30 00:46:13

Tio
Member
Registered: 2021-09-26
Posts: 92

Re: Open only specific window under mouse coursor

This is the script I have now, based on your suggestions:

#!/bin/bash
# If the window is registered with X: close it and exit script
if xdotool windowunmap $(xdotool search --onlyvisible --class "xfce4-appfinder") >/dev/null 2>&1; then
   exit
fi

# get screen dimensions [ $sw $sh ]
eval $(xrandr | grep \* | awk '{print $1}' | awk -F'x' '{printf "sw=%d\nsh=%d",$1, $2}')

# get mouse pointer location [ $X $Y ]
eval $(xdotool getmouselocation --shell | head -2)

# start the app
xfce4-appfinder &

# start the app and pause for window to load
xfce4-appfinder & until xdotool search --onlyvisible --class "xfce4-appfinder" >/dev/null 2>&1; do sleep .1; done

# get appfinder dimensions [ $wx $wy $ww $wh ]
eval $(wmctrl -lG | grep "Application Finder" | awk '{printf "wx=%d\nwy=%d\nww=%d\nwh=%d",$3, $4, $5, $6}')

# get new window x value ensuring it remains on screen
	# if mouse x + window width is greater than screen width, then move new window x to the left to fit
if [ $((X+ww)) -gt $sw ]; then X=$((sw-ww)); fi

# get new window y value ensuring it remains on screen
	# if mouse y + window height is greater than screen height, then move new window y up to fit
if [ $((Y+wh)) -gt $sh ]; then Y=$((sh-wh)); fi

# move the window to the mouse pointer, while fitting on the screen
xdotool getactivewindow windowmove $X $Y

Offline

#17 2021-11-30 00:51:25

Tio
Member
Registered: 2021-09-26
Posts: 92

Re: Open only specific window under mouse coursor

ToZ wrote:
Tio wrote:

Hmmm I get the same behavior honestly. But I have a question: xfce allows you to select "place window under the mouse cursor" and if that is selected appfinder opens correctly near the launcher for appfinder. But it also does it for all windows, of course...so isn't there a way to use that option in XFCE but only for the appfinder?

Unfortunately, that setting is an all-or-nothing setting.

Oh ok...thanks for the clarification!

Offline

#18 2021-11-30 01:16:44

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: Open only specific window under mouse coursor

Tio wrote:

Also the bottom part is cut from the appfinder window. Can it be positioned a bit more on top?

...snip...

Edit: This is probably better: Assuming your panel width is 42, change the line:

eval $(xrandr | grep \* | awk '{print $1}' | awk -F'x' '{printf "sw=%d\nsh=%d",$1, $2}')

...to:

eval $(xrandr | grep \* | awk '{print $1}' | awk -F'x' '{printf "sw=%d\nsh=%d",$1, $2-42}')

Last edited by ToZ (2021-11-30 01:23:30)


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#19 2021-11-30 02:21:29

Misko_2083
Member
Registered: 2015-10-13
Posts: 191
Website

Re: Open only specific window under mouse coursor

^Again 42: Answer to the Ultimate Question of Life, the Universe, and Everything. big_smile

I think this will do:

#!/bin/bash

# If the window is registered with X: close it and exit script
if xdotool windowunmap $(xdotool search --onlyvisible --class "xfce4-appfinder") >/dev/null 2>&1; then
   exit
fi

# get screen dimensions [ $sw $sh ] from the curent workspace
eval $(wmctrl -d | awk '{ if ($2 == "'*'") print $9}' | awk -F'x' '{printf "sw=%d\nsh=%d", $1, $2}')

# start the app and wait for window to register with X
xfce4-appfinder & until xdotool search --onlyvisible --class "xfce4-appfinder" >/dev/null 2>&1; do sleep .1; done

win_id=$(xdotool search --onlyvisible --class "xfce4-appfinder")

# get mouse pointer location [ $X $Y ]
eval $(xdotool getmouselocation --shell | head -2)

# get appfinder dimensions [ $x $y $w $h ]
eval $(xwininfo -id "$win_id" |
      sed -n -e "s/^ \+Absolute upper-left X: \+\([0-9]\+\).*/x=\1/p" \
             -e "s/^ \+Absolute upper-left Y: \+\([0-9]\+\).*/y=\1/p" \
             -e "s/^ \+Width: \+\([0-9]\+\).*/w=\1/p" \
             -e "s/^ \+Height: \+\([0-9]\+\).*/h=\1/p" )

extents=$(xprop _NET_FRAME_EXTENTS -id "$win_id" | grep "NET_FRAME_EXTENTS" | cut -d '=' -f 2 | tr -d ' ')
bl=$(echo $extents | cut -d ',' -f 1) # width of left border
br=$(echo $extents | cut -d ',' -f 2) # width of right border
t=$(echo $extents | cut -d ',' -f 3)  # height of title bar
bb=$(echo $extents | cut -d ',' -f 4) # height of bottom border

let x=$x-$bl
let y=$y-$t
let w=$w+$bl+$br
let h=$h+$t+$bb

# get new window x value ensuring it remains on screen
	# if mouse x + window width is greater than screen width, then move new window x to the left to fit
if [ $((X+w)) -gt $sw ]; then X=$((sw-w)); fi

# get new window y value ensuring it remains on screen
	# if mouse y + window height is greater than screen height, then move new window y up to fit
if [ $((Y+h)) -gt $sh ]; then Y=$((sh-h)); fi

# move the window to the mouse pointer, while fitting on the workarea
xdotool windowmove "$win_id" $X $Y

Last edited by Misko_2083 (2021-11-30 02:22:48)


Do you want to exit the Circus?
https://www.youtube.com/watch?v=ZJwQicZHp_c

Offline

#20 2021-11-30 02:48:51

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: Open only specific window under mouse coursor

Perfect.

@Misko_2083, do you know if its possible to start an X window app (e.g. appfinder) unmapped, move it to the proper location, then map it on the screen?

^Again 42: Answer to the Ultimate Question of Life, the Universe, and Everything. big_smile

Yes. I purposefully create my side panel to be 42 pixels wide for this purpose. It is the answer.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#21 2021-11-30 17:49:52

Misko_2083
Member
Registered: 2015-10-13
Posts: 191
Website

Re: Open only specific window under mouse coursor

ToZ wrote:

Perfect.

@Misko_2083, do you know if its possible to start an X window app (e.g. appfinder) unmapped, move it to the proper location, then map it on the screen?

I don't know if that's possible. Mapping the window off-srceen with the devilspie and moving it to the right location, maybe.
The detection of a new window can be faster if, instead of sleep .1, _NET_ACTIVE_WINDOW property is monitored with

xprop -spy -root 32x '\t$0\n' _NET_ACTIVE_WINDOW

Or maybe _NET_CLIENT_LIST?
So when the window gets focus or is added to the window list it would be moved faster with xdotool.
Still some delay would be visible because the window manager positions the window.

There was Hitchhiker's Guide to the Galaxy movie the other day on TV...


Do you want to exit the Circus?
https://www.youtube.com/watch?v=ZJwQicZHp_c

Offline

#22 2021-11-30 21:02:01

Tio
Member
Registered: 2021-09-26
Posts: 92

Re: Open only specific window under mouse coursor

I tried the last script that @Misko_2083 posted (and thanks a lot) but doesn't work well. I am a bit concerned for this not to become to hacky big_smile. I thought maybe there is a possibility to use the XFCE options to move the window under the mouse pointer, only for a particular app. That would have been great. You think using such ways, as you guys suggested above, will always have a delay and may not work well if I change the launcher from a horizontal to a vertical position, or the panel's position overall?

Offline

Board footer

Powered by FluxBB