2

If I want to run GUI software on my Linux machine, I can do it without a window manager, but I can not discover a way to maximize the window. Is there a reliable way to maximize a window in an x server without a window manager?

2

X servers don't have a notion of “maximized” window. To maximize a window, instruct the application to use a window size that matches the screen size. You can use xdotool for that, though it may be a little difficult to select the window without a window manager — many ways to enumerate and single out windows rely on a window manager.

dimensions=$(xdpyinfo | sed 's/^ *dimension * : *\([0-9]*x[0-9]*\).*/\1/p')
windowid=…
xdotool windowmove "$windowid" 0 0 windowsize "${dimensions%x*}" "${dimensions#*x}"
0

I would like to open all my text files with Sublime Text, but it does not support a --maximize command line argument, and it either does not remember it window state on Linux and always open unmaximized.

Then, after researching I built this script:

#!/usr/bin/env bash
# run it with /home/user/maximize.sh "Sublime Text" /usr/bin/subl -n
eval "\"$2\" \"$3\" \"$4\" \"$5\" \"$6\" \"$7\" \"$8\" \"${@:9}\""

while [ true ]
do
    FocusApp=`xdotool getwindowfocus getwindowname`

    if [[ "$FocusApp" == *"$1"* ]];
    then
        # xdotool key super+Up
        wmctrl -ir $(xdotool getactivewindow) -b add,maximized_vert,maximized_horz
        break
    fi
done

You need to install these two things:

sudo apt-get install wmctrl xdotool 

I am not using ``xdotool` to maximize the window because it seems to be bugging with my XFCE4 and when unmaximizing the window, its default size is set to whole window size, i.e., when maximizing the window, it also changed the window size to the match the whole screen size.

References:

  1. How to execute a command on window focus/unfocus?
  2. How to send keystrokes (F5) from terminal to a GUI program?
  3. https://superuser.com/questions/382616/detecting-currently-active-window
  4. https://superuser.com/questions/850145/how-to-use-wmctrl-to-activate-window-of-a-given-class
  5. https://askubuntu.com/questions/703628/how-to-close-minimize-and-maximize-a-specified-window-from-terminal
  • 1
    Are you running a window manager? Without a normal window manager, just using Xepher, xdotool getactivewindow returns Your windowmanager claims not to support _NET_ACTIVE_WINDOW, so the attempt to query the active window aborted. – Craig Hicks Jul 9 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.