LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 02-25-2020, 10:27 PM   #1
babag
Member
 
Registered: Aug 2003
Posts: 419

Rep: Reputation: 31
kubuntu - run script from desktop icon?


edit:
oops. this problem may have always been the case. looks like the behavior described below is the same on the old system. i must have always run the script from a taskbar icon and never from the desktop icon. both systems work correctly from the taskbar icon and both systems also have the focus issue from the desktop icon. makes some sense when i think about it. would still be interesting to hear if it would be possible to make this work from the desktop icon. thanks and sorry.
end edit

i just rebuilt my system with a fresh install and a script (see below) i regularly use has started behaving oddly.

the script moves the active window to a specific position on a very large desktop. i have it because sometimes i will open a window while working and, depending on the application, the new window will open behind something. in this case, i just click a desktop or taskbar icon and the window is repositioned to a place where i can see and grab it.

since the rebuild, though, clicking the icon does not work. it just moves all of my desktop icons, as a group, slightly. running the script from a konsole window via command line does reposition the konsole window to the correct position.

it looks to me like i may have missed a setting somewhere in the rebuild that is causing the active window to lose focus as soon as i click the icon, thus, telling the script to move the desktop and not what had been the active window.

anyone know how to fix this?

thanks,
babag


Code:
#!/bin/sh
#
# Move the current window to the next monitor.
#
# Only works on a horizontal monitor setup.
# Also works only on one X screen (which is the most common case).
#
# Props to
# http://icyrock.com/blog/2012/05/xubuntu-moving-windows-between-monitors/
#
# Unfortunately, both "xdotool getwindowgeometry --shell $window_id" and
# checking "-geometry" of "xwininfo -id $window_id" are not sufficient, as
# the first command does not respect panel/decoration offsets and the second
# will sometimes give a "-0-0" geometry. This is why we resort to "xwininfo".

screen_width=`xdpyinfo | awk '/dimensions:/ { print $2; exit }' | cut -d"x" -f1`
display_width=`xdotool getdisplaygeometry | cut -d" " -f1`
window_id=`xdotool getactivewindow`

# Remember if it was maximized.
window_state=`xprop -id $window_id _NET_WM_STATE | awk '{ print $3 }'`

# Un-maximize current window so that we can move it
wmctrl -ir $window_id -b remove,maximized_vert,maximized_horz

# Read window position
x=`xwininfo -id $window_id | awk '/Absolute upper-left X:/ { print $4 }'`
y=`xwininfo -id $window_id | awk '/Absolute upper-left Y:/ { print $4 }'`

# Subtract any offsets caused by panels or window decorations
x_offset=`xwininfo -id $window_id | awk '/Relative upper-left X:/ { print $4 }'`
y_offset=`xwininfo -id $window_id | awk '/Relative upper-left Y:/ { print $4 }'`
x=`expr $x - $x_offset`
y=`expr $y - $y_offset`

# Compute new X position
new_x=`expr $x + $display_width`

# If we would move off the right-most monitor, we set it to the left one.
# We also respect the window's width here: moving a window off more than half its width won't happen.
width=`xdotool getwindowgeometry $window_id | awk '/Geometry:/ { print $2 }'|cut -d"x" -f1`
if [ `expr $new_x + $width / 2` -gt $screen_width ]; then
  new_x=`expr $new_x - $screen_width`
fi

# Don't move off the left side.
if [ $new_x -lt 0 ]; then
  new_x=0
fi

## Move the window
#xdotool windowmove $window_id $new_x $y

# Move the window to specific BabaG monitor setup location
#new_x=3360
#y=2160
new_x=3605
y=2190
xdotool windowmove $window_id $new_x $y

# Maximize window again, if it was before
if [ "${window_state}" = "_NET_WM_STATE_MAXIMIZED_HORZ," ]; then
  wmctrl -ir $window_id -b add,maximized_vert,maximized_horz
fi

Last edited by babag; 02-25-2020 at 10:56 PM.
 
Old 02-26-2020, 12:49 PM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,840

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
probably you will find something useful here: https://stackoverflow.com/questions/...topmost-window
 
Old 02-28-2020, 11:34 AM   #3
babag
Member
 
Registered: Aug 2003
Posts: 419

Original Poster
Rep: Reputation: 31
thanks!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mouse wheel VOLUME control icon , NETWORK control icon on MATE's desktop panel on CentOS 7 disappeared primorec Linux - Desktop 0 07-31-2018 05:45 PM
Script should run clicking on desktop icon on openbox beaglebone black. sd.israr@gmail.com Linux - Embedded & Single-board computer 2 01-03-2015 06:04 AM
ubuntu-desktop vs. kubuntu-desktop vs. xubuntu-desktop vs. lubuntu-desktop vs. unity Kenny_Strawn Ubuntu 18 05-13-2011 09:20 AM
script to move desktop icon to desktop/escritorio, how to know language? permalac Linux - Newbie 3 01-10-2009 08:49 AM
My Network Browsing desktop icon is gone > my network browsing desktop icon i kkempter SUSE / openSUSE 1 01-12-2006 12:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 04:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration