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

前端 未结 2 1488
青春惊慌失措
青春惊慌失措 2021-01-03 03:02

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

相关标签:
2条回答
  • 2021-01-03 03:25

    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()
    
    0 讨论(0)
  • 2021-01-03 03:34

    Do you mean making the window fullscreen?

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

    0 讨论(0)
提交回复
热议问题