LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to get the x and the y size of Cinnamon desktop, without the task bar ? (https://www.linuxquestions.org/questions/programming-9/how-to-get-the-x-and-the-y-size-of-cinnamon-desktop-without-the-task-bar-4175700731/)

Lennard37 09-16-2021 07:29 PM

How to get the x and the y size of Cinnamon desktop, without the task bar ?
 
How to get the x and the y size of Linux Mint Ubuntu Edition Cinnamon desktop, without the task bar (can be its called without gratification) ?

I have found 3 partly solutions.

Partly solution 1:

Code:

wmctrl -lG
0x04000003 -1 0    0    1366 728  pc_name desktop
# ...
# ...
# ...
0x04e00003  0 0    48  1366 703  computer LinuxQuestions.org - Post New Thread - Mozilla Firefox

How to get the value 1366 and 728 for output on follow way ?
Code:

echo $x
echo $y

Partly solution 2:

Code:

xdotool getwindowgeometry [FensterID z.B. 0x012345678]
# Output
Code:

Window 012345678
  Position: 0,0 (screen: 0)
  Geometry: 1366x728

# little bit filtered
Code:

xdotool getwindowgeometry 0x04000003 | grep Geometry
# Output
Code:

Geometry: 1366x728
# Kommandosobstitution
Code:

var="$( xdotool getwindowgeometry 0x04000003 | grep Geometry )"
echo $var

How to get ?
Code:

echo $x
echo $y

Partly solution 3:

Code:

wmctrl -d
# Output
Code:

0  * DG: 1366x768  VP: 0,0  WA: 0,0 1366x728  Workspace 1
1  - DG: 1366x768  VP: N/A  WA: 0,0 1366x728  Workspace 2
2  - DG: 1366x768  VP: N/A  WA: 0,0 1366x728  Workspace 3
3  - DG: 1366x768  VP: N/A  WA: 0,0 1366x728  Workspace 4

Code:

wmctrl -d | grep "Workspace 1"
# Output
Code:

0  * DG: 1366x768  VP: 0,0  WA: 0,0 1366x728  Workspace 1
Wanted output:
Code:

echo $x
1366

echo $y
728

I am looking for a solution which don't need AWK.

michaelk 09-16-2021 08:28 PM

A couple of examples for your first question using cut.
Code:

x=$(xdotool getdisplaygeometry | cut -d ' ' -f1 )
y=$(xdotool getdisplaygeometry | cut -d ' ' -f2 )
echo "x=$x"
echo "y=$y"

x=$(wmctrl -lG | grep Desktop | tr -s ' ' | cut -d ' ' -f5 )
y=$(wmctrl -lG | grep Desktop | tr -s ' ' | cut -d ' ' -f6 )

echo "x=$x"
echo "y=$y"


boughtonp 09-17-2021 06:15 AM


 
I would assume there is an X/Wayland way to do this that isn't specific to Mint or Cinnamon.

Yep, a quick search reveals xprop and _NET_WORKAREA which is calculated "by taking the current page minus space occupied by dock and panel windows"

Code:

$ xprop -root _NET_WORKAREA _NET_DESKTOP_GEOMETRY
_NET_WORKAREA(CARDINAL) = 0, 0, 1280, 764
_NET_DESKTOP_GEOMETRY(CARDINAL) = 0, 0, 1280, 800

Easy enough to then use cut/awk/whatever to extract the numbers.


Lennard37 09-17-2021 06:19 AM

Thanks, thats looking its on right way.

By the follow I get 1366 x 768 as output, but I need the range of the display ( in this case 1366 x 728 ) which dont have menus from Cinnamon and is available to show other windows. It can be I have to add the "wid" behind the "xdotool getdisplaygeometry" for this.

Quote:

Originally Posted by michaelk (Post 6284801)
A couple of examples for your first question using cut.
Code:

x=$(xdotool getdisplaygeometry | cut -d ' ' -f1 )
y=$(xdotool getdisplaygeometry | cut -d ' ' -f2 )
echo "x=$x"
echo "y=$y"



By follow one I dont get a output on this time:
Quote:

Originally Posted by michaelk (Post 6284801)
A couple of examples for your first question using cut.
Code:

x=$(wmctrl -lG | grep Desktop | tr -s ' ' | cut -d ' ' -f5 )
y=$(wmctrl -lG | grep Desktop | tr -s ' ' | cut -d ' ' -f6 )

echo "x=$x"
echo "y=$y"



Lennard37 09-17-2021 06:41 AM

Quote:

Originally Posted by boughtonp (Post 6284871)
I would assume there is an X/Wayland way to do this that isn't specific to Mint or Cinnamon.

Code:

$ xprop -root _NET_WORKAREA _NET_DESKTOP_GEOMETRY
_NET_WORKAREA(CARDINAL) = 0, 0, 1280, 764
_NET_DESKTOP_GEOMETRY(CARDINAL) = 0, 0, 1280, 800

Easy enough to then use cut/awk/whatever to extract the numbers.

Thats great. The follow give me a output which is including the wanted x=1366 and y=728 value:
Code:

xprop -root _NET_WORKAREA
# output
_NET_WORKAREA(CARDINAL) = 0, 0, 1366, 728, 0, 0, 1366, 728, 0, 0, 1366, 728, 0, 0, 1366, 728

Now I can try to get this working as follow:
Code:

echo "x=$x"
echo "y=$y"

Thats what I have on this time.:
Code:

x=$(xprop -root _NET_WORKAREA  | tr -s ' ' | cut -d ' ' -f5)
user@computer:~$ echo "x=$x"
x=1366,

Code:

y=$(xprop -root _NET_WORKAREA  | tr -s ' ' | cut -d ' ' -f6)
user@computer:~$ echo "x=$x"
y=1366,

How to remove the "," from Output "1366," and "728," ?

boughtonp 09-17-2021 06:48 AM


 
There's plenty of ways to get just the relevant values, using cut/awk/grep/etc.

Possibly the simplest way to get them into separate variables is to use Bash "[[" and "=~" which performs a regex match and puts the captured groups into an array, for example:

Code:

coords=$(xprop -root _NET_WORKAREA)
[[ "$coords" =~ ([0-9]+),\ ([0-9]+)$ ]]
echo "x=${BASH_REMATCH[1]}"
echo "y=${BASH_REMATCH[2]}"

But since you're getting four sets output you'll first want to check the xprop manual I linked above to confirm the options for only getting the screen/desktop you're interested in before doing that.


michaelk 09-17-2021 07:38 AM

Code:

_NET_WORKAREA(CARDINAL) = 0, 0, 1366, 728, 0, 0, 1366, 728, 0, 0, 1366, 728, 0, 0, 1366, 728
        f1                f2  f3  f4

Code:

x=$(xprop -root _NET_WORKAREA  | tr -s ' ' | cut -d ' ' -f5)
Change the cut separator from a space ' ' to a ','

Code:

x=$(xprop -root _NET_WORKAREA  | cut -d ',' -f3)
x=$(xprop -root _NET_WORKAREA  | cut -d ',' -f4)

The only caveat is that x and y contain a leading space.
x= 1366
Code:

x=$(xprop -root _NET_WORKAREA  | cut -d ',' -f3 | xargs echo -n)
x=$(xprop -root _NET_WORKAREA  | cut -d ',' -f4 | xargs echo -n)

Add xargs to remove extra spaces.
The "tr -s ' ' " command was used to "shrink" the number of white spaces between numbers in the other commands but not necessary with xprop.

Lennard37 09-17-2021 08:10 AM

Quote:

Originally Posted by michaelk (Post 6284892)
Code:

_NET_WORKAREA(CARDINAL) = 0, 0, 1366, 728, 0, 0, 1366, 728, 0, 0, 1366, 728, 0, 0, 1366, 728
        f1                f2  f3  f4

Code:

x=$(xprop -root _NET_WORKAREA  | tr -s ' ' | cut -d ' ' -f5)
Change the cut separator from a space ' ' to a ','

Code:

x=$(xprop -root _NET_WORKAREA  | cut -d ',' -f3)
x=$(xprop -root _NET_WORKAREA  | cut -d ',' -f4)

The only caveat is that x and y contain a leading space.
x= 1366
Code:

x=$(xprop -root _NET_WORKAREA  | cut -d ',' -f3 | xargs echo -n)
x=$(xprop -root _NET_WORKAREA  | cut -d ',' -f4 | xargs echo -n)

Add xargs to remove extra spaces.
The "tr -s ' ' " command was used to "shrink" the number of white spaces between numbers in the other commands but not necessary with xprop.

Thats my preferd solution.
Thanks for this and the guide to do this in future possible by self.
Thanks

Thanks for the other solutions from other people too.
THX


All times are GMT -5. The time now is 05:59 PM.