我制作了这个 Python 脚本:
from gi.repository import Gtk, Gdk, GdkX11, Wnck
from subprocess import PIPE, Popen
class WindowError(Exception):
pass
def undecorate(aWindow):
gdkdis = GdkX11.X11Display.get_default()
gdkwin = GdkX11.X11Window.foreign_new_for_display(gdkdis, aWindow.get_xid())
gdkwin.set_decorations(Gdk.WMDecoration.BORDER)
def dropdown(aTitle):
Gtk.main_iteration()
screen = Wnck.Screen.get_default()
screen.force_update()
for window in screen.get_windows():
if window.get_name() == aTitle:
timestamp = Gtk.get_current_event_time()
undecorate(window)
window.set_skip_pager(True)
window.set_skip_tasklist(True)
window.stick()
window.pin()
window.maximize_horizontally()
window.set_geometry(Wnck.WindowGravity.STATIC,
Wnck.WindowMoveResizeMask.Y,
0, 0, -1, -1)
window.activate(timestamp)
window.unminimize(timestamp)
break
else:
raise WindowError('Window with title "{}" not found'.format(aTitle))
def getActive():
Gtk.main_iteration()
screen = Wnck.Screen.get_default()
screen.force_update()
return screen.get_active_window()
def main():
active = getActive()
if active.get_name() == 'Dropdown Terminal':
if active.is_minimized():
dropdown('Dropdown Terminal')
else:
active.minimize()
return
else:
try:
dropdown('Dropdown Terminal')
except WindowError:
Popen(['roxterm', '--profile=Dropdown'], stdout=PIPE, stderr=PIPE)
dropdown('Dropdown Terminal')
if __name__ == "__main__":
main()
它的作用是让 roxterm 表现得像 Guake。我遇到的唯一问题是当我打开一个新的 roxterm 实例并将窗口移动到 (0,0) 之后,窗口的最终 y 位置向下几个可见像素。我使用 wnck 库中的 set_geometry 函数来执行此操作。关于如何解决它的任何想法?谢谢。