I have two monitors set up above each other.
The primary monitor is the lower one, and has the two edge panels on the top and bottom of the display.
The setting looks something like this:
+---------------+
| |
| |
| |
| |
|-----------+---+
|'''''''''''|
| |
|,,,,,,,,,,,|
+-----------+
However, when I maximize a window on the screen with the panels, the panel between the two screens gets ignored, and the window maximizes partially behind it, hiding the top of the window (where the controls are). The same thing happens with the bottom panel, if I switch the panels to the upper monitor.
I ran into this problem while trying to configure a
snap-to script for a two monitor environment. Obviously, I had to sort this out before moving forward with the script.
The heart of the problem is the thing called "strut" which is basically a reserved space on the screen for a window.
Long story short, a strut for a window can be set with
xprop
.
You can find more information about the things I describe below on the
xprop manpage, the
ewmh reference page, and on the manpages of
xwininfo,
xrandr and
grep.
Let's get started!
First you'll need some information about your screen setup to know what you're doing is right.
Get the size of your virtual screen (you can skip this):
xprop -root | egrep '^(_NET_WORKAREA)'
I got this (I have 4 workspaces, this is why the numbers appear four times in a row):
_NET_WORKAREA(CARDINAL) = 0, 0, 1280, 1792, 0, 0, 1280, 1792, 0, 0, 1280, 1792, 0, 0, 1280, 1792
So my screen is 1280x1792 pixels, and it's one big virtual screen alltogether.
I know that my upper screen is 1280x1024 in resolution, and the lower one is 1024x768. If I needed to check this with a command, I would use
xrandr -q | grep '*'
Get the ID of the relevant panel (you'll have to click on the panel after you run this):
xwininfo | grep -w id
I got this:
xwininfo: Window id: 0x1600007 "Top Expanded Edge Panel"
Now I know the ID of the top panel is 0x1600007. I'll need this later.
Get an idea about the strut currently set for your panels (you can skip this):
xprop -id 0x1600007 | egrep '^(_NET_WM_STRUT_PARTIAL)'
I got this:
_NET_WM_STRUT_PARTIAL(CARDINAL) = 0, 0, 0, 0, 0, 0, 0, 0, 0, 1023, 0, 0
For a comparison, this is the same output for the bottom panel - notice the "24" in the fourth place:
_NET_WM_STRUT_PARTIAL(CARDINAL) = 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 1023
Now, plan your setting!
How to use ewmh _net_wm_strut_partial property?
The property you want to set is somewhat complicated. The lot of zeros and non-zeros you see above mean the following:
_NET_WM_STRUT_PARTIAL, left, right, top, bottom, left_start_y, left_end_y, right_start_y, right_end_y, top_start_x, top_end_x, bottom_start_x, bottom_end_x,CARDINAL[12]/32
This is still very confusig. I could sort out these settings for myself thanks to
this stackoverflow post.
The values are not independent of each other: they are groups. They have to be used together like this:
left & left_start_y & left_end_y
right & right_start_y & right_end_y
top & top_start_x & top_end_x
bottom & bottom_start_x & bottom_end_x
The trick is that you use only one group of values for one window setting. Choosing the one depends on the position you want the window to take.
I will show how to do this on my settings.
My screen dimensions are 1280x1792. The upper screen is 1280x1024, the lower is 1024x768 big.
If I want to reserve space on the bottom of this area, I will relate to this area with the "bottom" value group. So for a panel 1024x24 big, I'll use bottom = 24, bottom_start_x = 0, bottom_end_x = 1024. (because this is on my smaller screen).
Likewise, if I want to reserve space on the top of the two screen big area, I will relate to
this area with the "top" value group. So for a panel 1024x24 big,
I'll use top = 24, top_start_x = 0, top_end_x = 1280. (because this is on my bigger screen).
However, if I want to put the panel to the top of the lower, smaller screen, I will have to relate to the "left" group, because the left screen sides are the ones lined together (creating a dead area besides the right side of the lower screen).
Relating to the "left" group looks like this: left = 1024 (this is the width of my panel), left_start_y = 1024 (this is the height of the upper screen), left_end_y= 1048 (this is left_start_y plus the height of my panel (24)).
Reserving space on the upper screen for the bottom panel could be done with the "left" group, but I will demonstrate it with the "right" group. It will be: right = 1280 (with of panel), right_start_y = 1000 (which is the height of the upper screen minus the height of the panel (24)), right_end_y = 1024 (height of upper screen).
Generally, you define left, right, top and bottom relative to the left, right, top and bottom edge of the whole virtual screen, and you define the rest of the values in the regular coordinate system, the top left corner of the whole screen being x=0, y=0, and the bottom right corner being x= full width, y= full height.
Now I have all the values I want to set, and all the information to set them.
I will use
xprop -set
to set them.
xprop -id 0x1600007 -f _NET_WM_STRUT_PARTIAL 32c -set _NET_WM_STRUT_PARTIAL 1024,0,0,0,1024,1048,0,0,0,0,0,0
The meaning of options are:
-id 0x1600007
(this is the window ID I got from xwininfo)
-f _NET_WM_STRUT_PARTIAL 32c
(this is the format of the property I am about to set. for more info check out the manpage)
-set _NET_WM_STRUT_PARTIAL 1024,0,0,0,1024,1048,0,0,0,0,0,0
(this is the property and the values I am setting)
A future plan is to make the system automatically set this option for any kind of multi-monitor setup.
UPDATE:
I wrote a
script to calculate the position of the floating panel and set the strut for me (still manually):
#!/bin/bash
# (re)set panel struts on (different sized) dual monitor screen
#************************************************************
# what this script needs to do?
#############################################################
# PART 1
#************************************************************
# check if screen settings has been modified since the last time this script set the strut
## if yes: the panel position has to be recalculated
### check last modification date of /home/user/.config/monitors.xml
# check if panel strut has been removed anyhow (even when the screen setting has not changed)
## if yes: the strut has to be reset (to the previously used setting)
### comment: since strut gets removed by clicking the menu on the panel, how will it react it it is set back instantly
#############################################################
# PART 2
#************************************************************
# check for panel positions -- done
# set strut for panels -- done
#############################################################
# CONDITIONAL RUNNIG OF THE SCRIPT
# This script should work only if the full screen width < height, because this is the only case when the panel does not have a proper strut.
# Should this script run at all?
#read -a screen_geo < <(xwininfo -root | grep geometry | cut -f4 -s -d" " | awk 'BEGIN { FS="[x+]" } { print $1,$2 }')
#if [ "${screen_geo[0]}" -gt "${screen_geo[1]}" ]; then
#echo "this thingy should quit now, of stand by until screen settings are modified"
#else ### the program should modify the settings.
### however not this does nothing and the settings are modified anyway.
#fi
#############################################################
# PART 2
#************************************************************
# It should be decided which one is the floating panel, and the script should run editing only this panel.
# An array for all the panels (id numbers get in it)
read -a panels_id < <(wmctrl -l | grep "Panel" | awk '{ print $1 }' | tr '\n' ' ' | awk '{ print $1,$2}')
# Which panel is floating?
# A panel is floating if the first 4 values in the testpanel array are all 0.
for i in "${panels_id[@]}"; do
counter=0
read -a testpanel < <(xprop -id $i | egrep '^(_NET_WM_STRUT_PARTIAL)' | cut -f3- -d" " | awk 'BEGIN { FS="," } { print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12 }') # 0 0 0 0 0 0 0 0 0 1023 0 0
#echo ${testpanel[*]}
for j in "${testpanel[@]:0:4}"; do
if [ "$j" -gt "0" ]; then
let "counter = $counter + 1"
fi
done
if [ $counter -lt "1" ]; then
fl_id=$i
fi
done
#echo $fl_id
# Get important values for the floating panel to work with:
# geometry of the floating panel
read -a fl_geo < <(xwininfo -id $fl_id | grep geometry | cut -f4 -s -d" " | awk 'BEGIN { FS="[x+-]" } { print $1,$2,$3,$4 }') # 1024 24 0 1024
#echo ${fl_geo[*]}
# strut values of the floating panel
read -a fl_strut < <(xprop -id $fl_id | egrep '^(_NET_WM_STRUT_PARTIAL)' | cut -f3- -d" " | awk 'BEGIN { FS="," } { print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12 }') # 0 0 0 0 0 0 0 0 0 1023 0 0
#echo ${fl_strut[*]}
# Calculate correct strut position
# Should it be on the Left or on the Right?
# The panel is on the left side if there is less than two value in the strut array greater than 0.
counter=0
for i in "${fl_strut[@]}"; do
if [ "$i" -gt "0" ]; then
let "counter = $counter + 1"
fi
done
if [ $counter -lt "2" ]; then
side="left"
else
side="right"
fi
#echo $side
# Calculate the values for the strut position
# Usage: _NET_WM_STRUT_PARTIAL, left, right, top, bottom, left_start_y, left_end_y, right_start_y, right_end_y, top_start_x, top_end_x, bottom_start_x, bottom_end_x,CARDINAL[12]/32
left=0; right=0; top=0; bottom=0; left_start_y=0; left_end_y=0; right_start_y=0; right_end_y=0; top_start_x=0; top_end_x=0; bottom_start_x=0; bottom_end_x=0
# ${fl_geo[0]} width
# ${fl_geo[1]} height
# ${fl_geo[2]} x
# ${fl_geo[3]} y
if [ "$side" = "left" ]; then
left=${fl_geo[0]}
left_start_y=${fl_geo[3]}
left_end_y=$((${fl_geo[3]}+${fl_geo[1]}))
elif [ "$side" = "right" ]; then
right=${fl_geo[0]}
right_start_y=${fl_geo[3]}
right_end_y=$((${fl_geo[3]}+${fl_geo[1]}))
fi
# set correct strut for floating panel
# echo "xprop -id $fl_id -f _NET_WM_STRUT_PARTIAL 32c -set _NET_WM_STRUT_PARTIAL $left,$right,$top,$bottom,$left_start_y,$left_end_y,$right_start_y,$right_end_y,$top_start_x,$top_end_x,$bottom_start_x,$bottom_end_x"
xprop -id $fl_id -f _NET_WM_STRUT_PARTIAL 32c -set _NET_WM_STRUT_PARTIAL $left,$right,$top,$bottom,$left_start_y,$left_end_y,$right_start_y,$right_end_y,$top_start_x,$top_end_x,$bottom_start_x,$bottom_end_x
# set -x #activate debugging in normal run from here
# set +x #stop debugging in normal run from here
exit 0