使用GTK查找工作区大小(屏幕大小更少的任务栏)。

时间:2021-01-28 23:11:55

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.

但是窗口的底部由任务栏覆盖。

2 个解决方案

#1


9  

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


1  

Do you mean making the window fullscreen?

你是说要把窗户全打开吗?

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

Gtk具有使windows fullscreen和back的功能,可以看到gtk_window_fullscreen()和gtk_window_unfullscreen()。

#1


9  

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


1  

Do you mean making the window fullscreen?

你是说要把窗户全打开吗?

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

Gtk具有使windows fullscreen和back的功能,可以看到gtk_window_fullscreen()和gtk_window_unfullscreen()。