Encontrar el tamaño del espacio de trabajo (tamaño de pantalla menos la barra de tareas) usando GTK

StackOverflow https://stackoverflow.com/questions/502282

  •  20-08-2019
  •  | 
  •  

Pregunta

¿Cómo se crea una ventana principal que llena todo el escritorio sin cubrir (o quedar cubierto por) la barra de tareas y sin maximizarse ? Puedo encontrar el tamaño completo de la pantalla y configurar la ventana principal de acuerdo con esto:

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

pero la parte inferior de la ventana está cubierta por la barra de tareas.

¿Fue útil?

Solución

Usted está totalmente a merced de su administrador de ventanas para esto, y la cuestión clave aquí es:

  

sin maximizarse

Por lo tanto, nos quedan varios hacks, porque básicamente la maximización y el cambio de tamaño son dos cosas separadas, para que puedas recordar dónde estaba cuando no está maximizado.

Entonces, antes de mostrarte este horrible truco, te insto a que consideres usar la maximización adecuada y que estés contento con él.

Entonces aquí va:

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

Otros consejos

Do you mean making the window fullscreen?

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top