使用GTK查找工作空间大小(屏幕大小减去任务栏) [英] Finding the workspace size (screen size less the taskbar) using GTK

查看:197
本文介绍了使用GTK查找工作空间大小(屏幕大小减去任务栏)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建一个填充整个桌面的主窗口,而不覆盖(或覆盖)任务栏而不会被最大化?我可以找到整个屏幕大小,并相应地设置主窗口:

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

但窗口的底部被任务栏覆盖。 这是你窗口管理器的仁慈,而这里的关键问题是:


未被最大化

因此,在我向您展示这个可怕的黑客之前,我强烈建议您考虑使用适当的最大化并对它感到满意。 >

所以在这里:

 汇入gtk 

#甚至我很惭愧通过这
#设置一个一次性信号处理程序来检测大小变化
def _on_size_req(win,req):
x,y,w,h = win.get_allocation()
打印x,y,w,h#只是为了证明你的工作
win.disconnect(win.connection_id)
win.unmaximize()
win.window.move_resize(x, y,w,h)

#创建窗口,连接信号,然后使其最大化
w = gtk.Window()
w.show_all()
w .connection_id = w.connect('size-request',_on_size_req)
#最大化将触发信号处理程序一次,
#unmaximize,然后调整为先前设置的大小以实现最大化。
w.maximize()

#运行这个怪物
gtk.main()


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.

解决方案

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

这篇关于使用GTK查找工作空间大小(屏幕大小减去任务栏)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆