1

Recently, I came in contact with screen resizing on windows 7, and I find it very nice. It works like so:

    monitor 1                       monitor 2
-------------------------   ----------------------------
|          |            |   |             |            | 
|          |            |   |             |            |
|          |            |   |             |            |
|   1      |    2       |   |    3        |    4       |
|          |            |   |             |            |
|          |            |   |             |            |
|          |            |   |             |            |
-------------------------   ----------------------------

Say you have an application opened in monitor 1, currently in focus.

  • If you press mod4+up, it goes fullscreen on monitor 1 (that is, it covers areas 1 and 2).

  • If you press mod4+left, it goes halfscreen on monitor 1 (that is, it covers area 1).

  • If you press mod4+right, it goes halfscreen on monitor 1 (but now it covers area 2).

  • Press mod4+right again, and it goes halfscreen on monitor 2 (area 3)

  • Press mod4+right again, and it goes halfscreen on monitor 2 (area 4)

  • Press mod4+up again, and it goes fullscreen on monitor 2 (areas 3 and 4)

My question: I want to reproduce this behaviour, using a window manager independent trio of programs:

  • p_right moves right: goes from fullscreen in monitor 1 to area 2, to area 3, to area 4
  • p_left moves left
  • p_full makes the app fullscreen on the current monitor
  • p_right and p_left are clever: they only send the program to another monitor if there is one there.

Of course, then I´ll have to connect my applications to my window manager so that the programs get called when a key combination is pressed

How would I go about doing that? Do I have to program against X/Wayland, or is there some utility I can use, and my programs can become relatively trivial bash scripts?

Edit:

xdotool getactivewindow windowmove 21% 0 windowsize 21% 70%

The previous command sets a window position an size

xrandr | grep connected | grep -v disconnected | egrep '[0-9]+x[0-9]++[0-9x+]*' -o

This command gets the geometry of all monitors

I will post a full answer when it is ready

josinalvo
  • 6,947
  • 5
  • 37
  • 51
  • 1
    For X, there is wmctl which is compatible with most EWMH compliant window managers. They have a list of known compatible window managers on their site, including kwin and metacity. I don't know if there is a similar tool for Wayland, but due to their strict security policies I doubt that they allow you to resize and reposition windows programmatically. – danzel Jun 12 '19 at 09:51
  • I've just started tinkering in this area myself and found I had to use both wmctl and xdotool at the same time: xdotool how to select desktop send F5 and return? – WinEunuuchs2Unix Jun 21 '19 at 22:34
  • As an alternative to above listed tools You can familiarize yourself with tiling window managers like i3, awesome or xmonad to name a few... – Michal Przybylowicz Jun 21 '19 at 22:36

1 Answers1

0

What follows is a bash script, using both xdotool and xrandr that does the job. I will provide more details/new versions as it becomes possible/if people request it.

It does its job from the command line, and has to be configured on your window manager to start running when a certain key combination is pressed

first_monitor=`xrandr | grep connected | grep -v disconnected | egrep '[0-9]+x[0-9]++[0-9x+]*' -o | head -n 1`
#echo $first_monitor
number_monitors=`xrandr | grep connected | grep -v disconnected | egrep '[0-9]+x[0-9]++[0-9x+]*' -o | wc -l`
#echo $number_monitors

if [ $number_monitors -eq 2 ] 
then
   second_monitor=`xrandr | grep connected | grep -v disconnected | egrep '[0-9]+x[0-9]++[0-9x+]*' -o | tail -n 1`
fi
if [ $number_monitors -ne 2 ] 
then
   second_monitor='not there'
fi

size_first_monitor=`echo $first_monitor | awk 'BEGIN { FS="x" } { print $1 }'`
[ $second_monitor != 'not there' ] &&  size_second_monitor=`echo $second_monitor | awk 'BEGIN { FS="x" } { print $1 }'`

position_px=`xdotool getactivewindow getwindowgeometry | grep Position | awk '{print $2}' | awk 'BEGIN { FS="," } { print $1 }'`

position='outside'
(( $position_px < $size_first_monitor/2 )) && position='first_half_first_monitor'
(( $position_px >= $size_first_monitor/2 )) && (($position_px < $size_first_monitor)) && position='second_half_first_monitor'
if [ '$second_monitor' != 'not there' ] 
 then
 (( $position_px >= $size_first_monitor )) && (($position_px < $size_first_monitor+($size_second_monitor/2) )) && position='first_half_second_monitor'
 (($position_px >= $size_first_monitor+($size_second_monitor/2)  )) && position='second_half_second_monitor'
fi

height_first_monitor=`echo $first_monitor | awk 'BEGIN { FS="+" } { print $1 }'|awk 'BEGIN { FS="x" } { print $2 }'`
height_second_monitor=`echo $second_monitor | awk 'BEGIN { FS="+" } { print $1 }'|awk 'BEGIN { FS="x" } { print $2 }'`
height_first_monitor=$(( $height_first_monitor - 20 ))
height_second_monitor=$(( $height_second_monitor - 20 ))

first_position="xdotool getactivewindow windowmove 0 0 windowsize $(( $size_first_monitor/2 )) $height_first_monitor"
second_position="xdotool getactivewindow windowmove $(( $size_first_monitor/2 )) 0  windowsize $(( $size_first_monitor/2 )) $height_first_monitor"
third_position="xdotool getactivewindow windowmove $size_first_monitor 0  windowsize $(( $size_second_monitor/2 )) $height_second_monitor"
fourth_position="xdotool getactivewindow windowmove $(( $size_first_monitor + $size_second_monitor/2 )) 0 windowsize $(( $size_second_monitor/2 )) $height_second_monitor"

if [ "$1" == 'right' ]
then
   [ "$position" == 'first_half_second_monitor' ] && [ $second_monitor != 'not there' ]&& $fourth_position
   [ "$position" == 'second_half_first_monitor' ] && [ $second_monitor != 'not there' ]&& $third_position
   [ "$position" == 'first_half_first_monitor' ] && $second_position
fi

size_window=`xdotool getactivewindow  getwindowgeometry | grep Geometry | awk '{print $2}' | awk 'BEGIN { FS="x" } { print $1 }'`
if [ "$1" == 'left' ]
then
   [ "$position" == 'first_half_first_monitor' ] && $first_position
   [ "$position" == 'second_half_first_monitor' ] && $first_position
   [ "$position" == 'first_half_second_monitor' ] && [ $size_window != $size_second_monitor ] && $second_position
   [ "$position" == 'first_half_second_monitor' ] && [ $size_window == $size_second_monitor ] && $third_position
   [ "$position" == 'second_half_second_monitor' ] && $third_position
fi

echo $size_window
echo $size_second_monitor

max_first_monitor="xdotool getactivewindow windowmove 0 0  windowsize $size_first_monitor $height_first_monitor"
max_second_monitor="xdotool getactivewindow windowmove $size_first_monitor 0  windowsize $size_second_monitor $height_second_monitor"
if [ "$1" == 'maximize' ]
then
   [ "$position" == 'first_half_first_monitor' ] && $max_first_monitor
   [ "$position" == 'second_half_first_monitor' ] && $max_first_monitor
   [ "$position" == 'first_half_second_monitor' ] && $max_second_monitor
   [ "$position" == 'second_half_second_monitor' ] && $max_second_monitor
fi
josinalvo
  • 6,947
  • 5
  • 37
  • 51