Author Topic: Is There A Command Line Utility  (Read 5304 times)

Meanie

  • Hero Member
  • *****
  • Posts: 2803
    • View Profile
    • http://www.users.on.net/~hluc/myZaurus/
Is There A Command Line Utility
« Reply #15 on: March 15, 2007, 08:40:38 pm »
Quote
Quote
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...
« Last Edit: March 15, 2007, 09:35:15 pm by Meanie »
SL-C3000 - pdaXii13 build5.4.9 (based on pdaXrom beta3) / SL-C3100 - Sharp ROM 1.02 JP (heavily customised)
Netgear MA701 CF, SanDisk ConnectPlus CF, Socket Bluetooth CF, 4GB Kingston CF,  4GB pqi SD, 4GB ChoiceOnly SD, 2GB SanDisk SD USB Plus, 1GB SanDisk USB Plus, 1GB Transcend SD, 2GB SanDisk MicroSD with SD adaptor, Piel Frama Leather Case, GoldX 5-in-1 USB cable, USB hub, USB mouse, USB keyboard, USB ethernet, USB HDD, many other USB accessories...
(Zaurus SL-C3000 owner since March 14. 2005, Zaurus SL-C3100 owner since September 21. 2005)
http://members.iinet.net.au/~wyso/myZaurus - zBook3K

Antikx

  • Hero Member
  • *****
  • Posts: 1147
    • View Profile
    • http://tyrannozaurus.com
Is There A Command Line Utility
« Reply #16 on: March 15, 2007, 10:06:03 pm »
Quote
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.
Kanpai,
-Antikx (Twitter, Mugshot and PodNova)
C1000 - pdaXrom R198 (Celestial Environment)
tyrannozaurus.com
[img]http://www.tyrannozaurus.com/files/category_pictures/general_1.png\" border=\"0\" class=\"linked-sig-image\" /]
Zaurus news/blogs feed from Zaurus users
Free Windows, Linux, or Web RSS readers.
Featured pages at tyrannozaurus:
Sharp Petition, ScummVM, Cacko, pdaXii13, and Celestial Environment

daniel3000

  • Hero Member
  • *****
  • Posts: 1003
    • View Profile
    • http://
Is There A Command Line Utility
« Reply #17 on: March 16, 2007, 09:54:33 am »
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 :-)
 
Code: [Select]
#!/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?

Code: [Select]
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
« Last Edit: March 16, 2007, 11:01:47 am by daniel3000 »
SL-C3200 with weeXpc, based on pdaXrom 1.1.0beta3
HP 200LX with MS-DOS 5.0

daniel3000

  • Hero Member
  • *****
  • Posts: 1003
    • View Profile
    • http://
Is There A Command Line Utility
« Reply #18 on: March 16, 2007, 11:59:29 am »
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):


Code: [Select]
#!/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
SL-C3200 with weeXpc, based on pdaXrom 1.1.0beta3
HP 200LX with MS-DOS 5.0

Drake01

  • Full Member
  • ***
  • Posts: 226
    • View Profile
Is There A Command Line Utility
« Reply #19 on: March 16, 2007, 07:48:28 pm »
Quote
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.

Quote
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.
Device: SL-C3200 running pdaXii13v2 build 5.5.0
Networking: Symbol Spectrum24 WLAN card; Kingston CIO10T CF NIC
Storage: 4GB Transcend 150x SD; 16GB Transcend 133x CF; 4GB Seagate CF HDD; 4GB Patriot SD
HID: Logitech V450 Laser Mouse; generic silicone USB keyboard; 2 generic optical mice; stock plastic stylus
GPS: generic "UT-41" USB GPS Receiver
Case: neoprene case from my old Palm foldable keyboard

Antikx

  • Hero Member
  • *****
  • Posts: 1147
    • View Profile
    • http://tyrannozaurus.com
Is There A Command Line Utility
« Reply #20 on: March 16, 2007, 08:48:46 pm »
Great work so far dan3k! This will be a great addition to pdaXrom.
« Last Edit: March 16, 2007, 08:50:54 pm by Antikx »
Kanpai,
-Antikx (Twitter, Mugshot and PodNova)
C1000 - pdaXrom R198 (Celestial Environment)
tyrannozaurus.com
[img]http://www.tyrannozaurus.com/files/category_pictures/general_1.png\" border=\"0\" class=\"linked-sig-image\" /]
Zaurus news/blogs feed from Zaurus users
Free Windows, Linux, or Web RSS readers.
Featured pages at tyrannozaurus:
Sharp Petition, ScummVM, Cacko, pdaXii13, and Celestial Environment

daniel3000

  • Hero Member
  • *****
  • Posts: 1003
    • View Profile
    • http://
Is There A Command Line Utility
« Reply #21 on: March 17, 2007, 05:05:22 pm »
Quote
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
SL-C3200 with weeXpc, based on pdaXrom 1.1.0beta3
HP 200LX with MS-DOS 5.0