OESF Portables Forum
Model Specific Forums => Sharp Zaurus => Zaurus - pdaXrom => Topic started by: Meanie on March 14, 2007, 07:28:52 pm
-
before i attempt to write one of my own, is there a utility that can bring a running application such as xmms to the foreground?
what i want to do is to send xmms to the foreground if it its running when closing the Z's display. this would then allow me to control the music using the ok and slider on the back of the zaurus.
currently i need to alt tab it to the foreground before closing the display. i want to automate that
-
never mind, I wrote a small utility called xraise to do that
-
never mind, I wrote a small utility called xraise to do that
[div align=\"right\"][a href=\"index.php?act=findpost&pid=156352\"][{POST_SNAPBACK}][/a][/div]
Any chance of extending it so that it will check whether an app is running, if so bring to front, if not start it?
-
never mind, I wrote a small utility called xraise to do that
[div align=\"right\"][a href=\"index.php?act=findpost&pid=156352\"][{POST_SNAPBACK}][/a][/div]
Any chance of extending it so that it will check whether an app is running, if so bring to front, if not start it?
[div align=\"right\"][a href=\"index.php?act=findpost&pid=156356\"][{POST_SNAPBACK}][/a][/div]
that could be possible, but the problem is that the executable name and the window name are not always the same, ie for xmms, the binary is xmms, but the window name is XMMS. For leafpad, the binary is leafpad, but the window name is (Untitled)
it would probably be easier just to write a wrapper script say xlaunch which does a pidof to check if an app (the executable name) is running and if not, execute it, but if it is running, then use xwininfo -root -tree and parse the output to determine the window name of the running app and then use xraise to bring that window to the foreground...
-
Hi Meanie,
Such an xlaunch can look like this (I already wrote such a wrapper, but it is highly customized and huge, so I only post the general stuff here which is relevant to the thread):
#!/bin/bash
# Extract binary name from parameter:
BINARY=`echo "$1" | awk '{ print $1 }'`
BINARY=`basename "$BINARY"`
# Start $1 only if it does not run yet:
ps x | grep -v "$0" | awk '{print $5}' | grep "$BINARY$" > /dev/null
if [ $? -ne 1 ]; then
echo $1 is already running!
else
$1
fi
If you call this script "xlaunch" then you can run e.g. "xlaunch kopi" and kopi will only be started if it is not running yet.
The binary extraction also allows that you call a program with path and parameters:
xlaunch "/opt/some/binary --withparameter1 --andevenmore"
So now, how can we determine the window name from the process name in order to marry xlaunch with xraise?
daniel
-
Is there a reason, You can not use xmmscontrol?
In this case, it is no matter, if the xmms-window is in foreground or not.
Best regards
cmpayc
-
Is there a reason, You can not use xmmscontrol?
In this case, it is no matter, if the xmms-window is in foreground or not.
Best regards
cmpayc
[div align=\"right\"][a href=\"index.php?act=findpost&pid=156379\"][{POST_SNAPBACK}][/a][/div]
xmmscontrol which is by default configured in openbox causes the Z to almost lock up since it causes xmms to spawn too many instances which the Z cannot keep up with...
besides, this is just one use for xraise
-
So now, how can we determine the window name from the process name in order to marry xlaunch with xraise?
In my case I only need it for a few specific apps: eg sylpheed-claws, kopi, kapi, pwmanager etc, so for me maybe hardcoding it would be the easiest way.
-
just an fyi, someone from the unix users group here responded to your orig question with:
how about dbus-send or ... eesh ? depending upon your
wm... and yeah .. it would have to be wm specific ... at least afaik
-
So now, how can we determine the window name from the process name in order to marry xlaunch with xraise?
In my case I only need it for a few specific apps: eg sylpheed-claws, kopi, kapi, pwmanager etc, so for me maybe hardcoding it would be the easiest way.
[div align=\"right\"][a href=\"index.php?act=findpost&pid=156387\"][{POST_SNAPBACK}][/a][/div]
xwininfo -root -tree |grep -i appname
some smart parsing of the results from the above and then pass the result to xraise
eventually, xlaunch will:
check if app is running or not
if running use xwininfo or other method to determine app window name and use that with xraise to bring it to foreground
if not running, start app. launch fancy looking splash/throbber window
use xresizewindow to maximize app using same info (xwininfo) as was used for xraise
optionally, xlaunch can also disable dpms and restore settings when finished
also optionally, xlaunch can stop the volume applet and restart it after app has finished in case the app needs the mixer
-
Pretty neat. How about a corresponding xlower utility?
-
In my case I only need it for a few specific apps: eg sylpheed-claws, kopi, kapi, pwmanager etc, so for me maybe hardcoding it would be the easiest way.
[div align=\"right\"][a href=\"index.php?act=findpost&pid=156387\"][{POST_SNAPBACK}][/a][/div]
xwininfo -root -tree |grep -i appname
some smart parsing of the results from the above and then pass the result to xraise
the parsing would have to be smart indeed. grepping for kopi shows a LOT of lines...
desertrat: Hardcoding is difficult, because some apps change their window name depending on window content (kopi for example changes heavily, but also many other apps which print the name of the opened file into the title).
I'll think about this smart parsing, but first I'll have to understand the output myself
daniel
-
and if it's of interest someone posted this:
I think what you're looking for is wmctrl:
Description: control an EWMH/NetWM compatible X Window Manager
Wmctrl is a command line tool to interact with an EWMH/NetWM compatible X
Window Manager (examples include Enlightenment, icewm, kwin, metacity,
and sawfish).
Wmctrl provides command line access to almost all the features defined in the
EWMH specification. For example it can maximize windows, make them sticky, set
them to be always on top. It can switch and resize desktops and perform many
other useful operations.
For instance, on my currently running desktop:
oin$ wmctrl -l
0x00c00003 -1 oin Top Panel
0x00c0002d -1 oin Bottom Panel
0x00e00021 -1 oin Desktop
0x0280001f 0 oin root@gto: ~
0x02800f75 1 oin root@lemans: ~
0x02802735 2 oin Terminal
0x02600023 3 oin Holly Cole - I Will Wait for You
0x02a00020 2 oin linux icccm raise command - Google Search
0x028048a9 0 oin root@oin: ~
To switch my current screen to RhythmBox, and raise it to foreground:
oin$ wmctrl -a "Holly Cole - I Will Wait for You"
-
and if it's of interest someone posted this:
I think what you're looking for is wmctrl:
Description: control an EWMH/NetWM compatible X Window Manager
Wmctrl is a command line tool to interact with an EWMH/NetWM compatible X
Window Manager (examples include Enlightenment, icewm, kwin, metacity,
and sawfish).
Wmctrl provides command line access to almost all the features defined in the
EWMH specification. For example it can maximize windows, make them sticky, set
them to be always on top. It can switch and resize desktops and perform many
other useful operations.
For instance, on my currently running desktop:
oin$ wmctrl -l
0x00c00003 -1 oin Top Panel
0x00c0002d -1 oin Bottom Panel
0x00e00021 -1 oin Desktop
0x0280001f 0 oin root@gto: ~
0x02800f75 1 oin root@lemans: ~
0x02802735 2 oin Terminal
0x02600023 3 oin Holly Cole - I Will Wait for You
0x02a00020 2 oin linux icccm raise command - Google Search
0x028048a9 0 oin root@oin: ~
To switch my current screen to RhythmBox, and raise it to foreground:
oin$ wmctrl -a "Holly Cole - I Will Wait for You"
[div align=\"right\"][a href=\"index.php?act=findpost&pid=156439\"][{POST_SNAPBACK}][/a][/div]
now you tell me after i spend hours reading the X and wnck api
-
I think what you're looking for is wmctrl:[div align=\"right\"][a href=\"index.php?act=findpost&pid=156439\"][{POST_SNAPBACK}][/a][/div]
I don't seem to have that command on either my Zaurus or my desktop. Is this supposed to be a "stock" command?
-
I think what you're looking for is wmctrl:[div align=\"right\"][a href=\"index.php?act=findpost&pid=156439\"][{POST_SNAPBACK}][/a][/div]
I don't seem to have that command on either my Zaurus or my desktop. Is this supposed to be a "stock" command?
[div align=\"right\"][a href=\"index.php?act=findpost&pid=156463\"][{POST_SNAPBACK}][/a][/div]
its in debian. i am going to compile it for pdaXrom...
uploaded to the new packages announcement thread...
-
now you tell me after i spend hours reading the X and wnck api
[div align=\"right\"][a href=\"index.php?act=findpost&pid=156453\"][{POST_SNAPBACK}][/a][/div]
I'm not knowledgeable about this stuff so I was waiting for smarter heads to give me this info and pass it along to you.
-
Hi guys,
GREAT! Thank you Meanie and Antikx for wmctrl... just the tool which was missing!
Now I have written a script which does what I always looked for.
I wanted the application keys to be handled the way they are handled under Sharp/Cacko:
Push it to start the application.
Push it again when the app is running and it brings the window to the foreground.
VERY handy especially for calendar / address book etc!
Here are the relevant parts from my application wrapper script (call it "xlaunch" and let the application keys launch "xlaunch kopi" instead of just "kopi" etc.
Works great!
(since this is stripped from my huge wrapper script, I am not sure if this works as written here. But it sohuld at least give the idea and some implementation details):
I like these grep-awk-grep-awk pipes :-)
#!/bin/bash
ALLOWMOREINSTANCES=0
# Extract binary name from parameter:
BINARY=`echo "$1" | awk '{ print $1 }'`
BINARY=`basename "$BINARY"`
# Check if application already runs: (look for binary
# basename in ps x output column 5
ps x | grep -v "$0" | awk '{print $5}' | grep "$BINARY$" > /dev/null
if [ $? -ne 1 ]; then
# Program already runs. Bring it to foreground
# except if "ALLOWMOREINSTANCES" is set to 1 for the app.
echo $0: $1 is already running.
if [ $ALLOWMOREINSTANCES -eq 0 ]; then
BINPID=`ps x | grep -v "$0" | awk '{print $1 " " $5}' | grep "$BINARY$" | awk '{print $1}'`
echo DEBUG: PID of $BINARY is $BINPID.
BINWINID=`wmctrl -l -p | awk '{print $1 " " $3}' | grep " $BINPID$"`
echo DEBUG: BINWINID of $BINARY is $BINWINID
wmctrl -i -a "$BINWINID"
exit 0
fi
fi
#Start application:
echo $0: $1 is starting. Please wait...
$1
ERRCODE=$?
echo "($1)" exited with errorcode "$ERRCODE".
Now, I'd like to maximize all application windows by default after the app is started using the wrapper script.
Any idea how to do that?
wmctrl -i -r $BINWINID -b add,maximized_vert,maximized_horz
would do this (and does this, I have tested it), but the difficult part is to know when the window has been created and just after that do the maximize.
Some applications need a lot of time to generate their main window.
I thought of implementing a while loop with one pass per second which tests if there is already a window for the PID, and if there is, maximize it.
But maybe someone knows a more elegant solution?
Thanks
daniel
-
Okay, I implmented the maximizing too, now, using that while loop I suggested.
This is the new code (replaced the last three lines of above script with the new mechanism):
#!/bin/bash
ALLOWMOREINSTANCES=0
# Extract binary name from parameter:
BINARY=`echo "$1" | awk '{ print $1 }'`
BINARY=`basename "$BINARY"`
# Check if application already runs: (look for binary
# basename in ps x output column 5
ps x | grep -v "$0" | awk '{print $5}' | grep "$BINARY$" > /dev/null
if [ $? -ne 1 ]; then
# Program already runs. Bring it to foreground
# except if "ALLOWMOREINSTANCES" is set to 1 for the app.
echo $0: $1 is already running.
if [ $ALLOWMOREINSTANCES -eq 0 ]; then
BINPID=`ps x | grep -v "$0" | awk '{print $1 " " $5}' | grep "$BINARY$" | awk '{print $1}'`
echo DEBUG: PID of $BINARY is $BINPID.
BINWINID=`wmctrl -l -p | awk '{print $1 " " $3}' | grep " $BINPID$"`
echo DEBUG: BINWINID of $BINARY is $BINWINID
wmctrl -i -a "$BINWINID"
exit 0
fi
fi
#Start application:
echo $0: $1 is starting. Please wait...
# NEW CODE FOR MAXIMIZING:
MAXIMIZE=1
$1 &
PROCESSID=$!
WINDOWEXISTS=0
if [ $MAXIMIZE -eq 1 ]; then
while [ $WINDOWEXISTS = 0 ]; do
sleep 1
WINDOWID=`wmctrl -l -p | awk '{print $1 " " $3}' | grep " $PROCESSID$"`
if [ $? -eq 0 ]; then
WINDOWEXISTS=1
wmctrl -i -r $WINDOWID -b add,maximized_vert,maximized_horz
fi
done
fi
This works for all programs of which the first appearing window is the program window, i.e. most programs.
However, programs which show a splash screen, e.g Streamtuner, are not maximized, because the algorithm above detects the splash screen as the program window and tries to maximize that one.
Any idea how to work aroud that?
daniel
-
Okay, I implmented the maximizing too, now, using that while loop I suggested.
[div align=\"right\"][a href=\"index.php?act=findpost&pid=156511\"][{POST_SNAPBACK}][/a][/div]
This does sound pretty slick... and should be a good workaround for windows that don't have a "start maximized" option.
However, programs which show a splash screen, e.g Streamtuner, are not maximized, because the algorithm above detects the splash screen as the program window and tries to maximize that one.
Any idea how to work aroud that?
daniel
[div align=\"right\"][a href=\"index.php?act=findpost&pid=156511\"][{POST_SNAPBACK}][/a][/div]
I suppose a somewhat manual way would be to create a file that lists the names of applications that have splash screens and then compare the current window to that list. Assuming the splash screen maintains the same PID as the app window, you could try grabbing the window location or size and then create a loop that checks for that to change. Or does the window ID change when the splash screen disappears and the actual app window is created? Window ID might be cleaner.
-
Great work so far dan3k! This will be a great addition to pdaXrom.
-
I suppose a somewhat manual way would be to create a file that lists the names of applications that have splash screens and then compare the current window to that list. Assuming the splash screen maintains the same PID as the app window, you could try grabbing the window location or size and then create a loop that checks for that to change. Or does the window ID change when the splash screen disappears and the actual app window is created? Window ID might be cleaner.
[div align=\"right\"][a href=\"index.php?act=findpost&pid=156548\"][{POST_SNAPBACK}][/a][/div]
Most applications have the ability to have the splash screen disabled (option --no-splash or --nosplash or in the preferences).
BUT: There are apps, e.g. dillo, which don't report a PID to wmctrl, so the mechanism won't work for these.
I have implemented a workaround for them, using the window name instead. If we add a manually created list of window name strings to the script, this will handle now really all kinds of windows.
I'll post that fix later here.
Remind me in case I should forget...
Still testing.
Also, just recompiling smplayer latest version with reduced initial window size so the status line is visible on first start...
Whan letting the launcher script maximize smplayer, smplayer is not able to switch to a smaller window for audio playback after start, so I will disable maximize for smplayer and instead let it use the slightly reduced window size.
Also still testing...
daniel