Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding the workspace size (screen size less the taskbar) using GTK

Tags:

python

pygtk

gtk

How do you create a main window that fills the entire desktop without covering (or being covered by) the task bar and without being maximized? I can find the entire screen size with and set the main window accordingly with this:

window = gtk.Window()
screen = window.get_screen()
window.resize(screen.get_width(), screen.get_height())

but the bottom of the window is covered by the task bar.

like image 645
Stacey Richards Avatar asked Feb 02 '09 05:02

Stacey Richards


2 Answers

You are totally at the mercy of your window manager for this, and the key issue here is:

without being maximized

So we are left with a number of hacks, because basically maximization and resizing are two separate things, in order that you might be able to remember where it was when it is unmaximized.

So before I show you this hideous hack, I urge you to consider using proper maximization and just be happy with it.

So here goes:

import gtk

# Even I am ashamed by this
# Set up a one-time signal handler to detect size changes
def _on_size_req(win, req):
    x, y, w, h = win.get_allocation()
    print x, y, w, h   # just to prove to you its working
    win.disconnect(win.connection_id)
    win.unmaximize()
    win.window.move_resize(x, y, w, h)

# Create the window, connect the signal, then maximise it
w = gtk.Window()
w.show_all()
w.connection_id = w.connect('size-request', _on_size_req)
# Maximizing will fire the signal handler just once,
# unmaximize, and then resize to the previously set size for maximization.
w.maximize()

# run this monstrosity
gtk.main()
like image 129
Ali Afshar Avatar answered Nov 16 '22 08:11

Ali Afshar


Do you mean making the window fullscreen?

Gtk has functions for making windows fullscreen and back, see gtk_window_fullscreen() and gtk_window_unfullscreen().

like image 1
ulidtko Avatar answered Nov 16 '22 07:11

ulidtko