LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-31-2012, 06:07 AM   #1
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Rep: Reputation: Disabled
Place active window centered horisontally and some position vertically


Hello folks!

In mplayer there's this option which can set mplayer window for example 50% horisontally and 20% vertically on start. So it will be right centered horizontally and somewhat upper vertically. Is there any program that can take currently active X window and set its position like this (in percentage)? I was looking through wmctrl, but it doesn't seem to have such functionality. I want to set a hotkey for this thing.
 
Old 08-31-2012, 07:08 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,576

Rep: Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341
PHP Code:
wmctrl -<WIN> -<MVARG>  Resize and move the window around the desktopThe format of the <MVARGargument is described below.
<
MVARG>              Specifies a change to the position and size
                       of the window
The format of the argument is:

                       <
G>,<X>,<Y>,<W>,<H>

                       <
G>: Gravity specified as a numberThe numbers are
                          defined in the EWMH specification
The value of
                          zero is particularly useful
it means "use the
                          default gravity of the window"
.
                       <
X>,<Y>: Coordinates of new position of the window.
                       <
W>,<H>: New width and height of the window.

                       
The value of -1 may appear in place of
                       any of the 
<X>, <Y>, <W> and <Hproperties
                       to left the property unchanged

see http://tomas.styblo.name/wmctrl/
and also http://www.semicomplete.com/projects.../xdotool.xhtml
 
Old 08-31-2012, 08:08 AM   #3
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Original Poster
Rep: Reputation: Disabled
Thanks, I didn't specify that I need to do it with window of various size. So I can't get X,Y positions by default. It's for smplayer, which has different size for almost every video.

Code:
Examples:

 xdotool getactivewindow windowmove 100 100    # Moves to 100,100
 xdotool getactivewindow windowmove x 100      # Moves to x,100
 xdotool getactivewindow windowmove 100 y      # Moves to 100,y
 xdotool getactivewindow windowmove 100 y      # Moves to 100,y
This will do but how to calculate what x and y should be?
 
Old 08-31-2012, 08:34 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,576

Rep: Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341
xwininfo will give the current values, you can calculate the required size/pos and finally move that given window
 
Old 08-31-2012, 10:14 AM   #5
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Original Poster
Rep: Reputation: Disabled
Lightbulb Almost done...

Thanks. So after working on a script (I didn't learn to script bash) I have this half-working script:
Code:
#!/bin/bash

WIDTH=`xwininfo -id $(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}') | grep Width | awk '{print $2}'`
HEIGHT=`xwininfo -id $(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}') | grep Height | awk '{print $2}'`

echo $WIDTH
echo $HEIGHT
echo " "

LEFT=`calc "(1680 - $WIDTH) / 2"`
TOP=`calc "(1050 - $HEIGHT) / 6"`
# ^^ this works

# check if the variable is not int and if it ain't - make it int
# and this part doesn't work
if [[ $LEFT = *[!0-9]* ]]; then
  LEFT=`echo $LEFT | awk '{printf("%d\n",$1 + 0.5)}'`
fi

if [[ $TOP = *[!0-9]* ]]; then
  TOP=`echo $TOP | awk '{printf("%d\n",$1 + 0.5)}'`
fi

echo $LEFT
echo $TOP

xdotool getactivewindow windowmove $LEFT $TOP
I execute the script and get:
Code:
$ ./window
1099
644
 
291
0
How to fix "if" part?

Last edited by Mr. Alex; 08-31-2012 at 12:17 PM.
 
Old 08-31-2012, 01:02 PM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,576

Rep: Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341
probably you can use expr: http://ss64.com/bash/expr.html it cannot handle floating numbers, so you will have integers.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trouble with window position kaelthas Linux - Software 4 04-22-2011 09:42 AM
How do you set window position? golmschenk Linux - Software 1 02-25-2010 01:06 PM
setting the window position in X knobby67 Programming 4 04-29-2009 11:38 AM
Window Position txmedic03 Linux - General 1 03-26-2007 11:10 PM
fluxbox window position BroX Linux - Software 0 12-15-2003 05:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:32 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration