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

可紊 提交于 2020-01-21 03:28:27

问题


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.


回答1:


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()



回答2:


Do you mean making the window fullscreen?

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



来源:https://stackoverflow.com/questions/502282/finding-the-workspace-size-screen-size-less-the-taskbar-using-gtk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!