Guake terminal with mlti-monitors

Guake终端在多显示器环境下无法随意切换屏幕,通过同事提供的patch和升级gtk版本解决了部分问题,但出现Alt+Tab切换后F12闪烁的异常。经过对pygtk的研究,找到了修复这个问题的patch,但可能未进行全面测试,欢迎反馈和改进。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一直使用Guake终端,感觉蛮好用的,快速的切入切出感觉很爽。但是由于我在工作室的时候会使用很多显示器,多屏令guake表现不尽如我意。我不能随意的把guake终端放到我正在操作的屏幕上使用。


针对这个问题,有一次我和同事说起,他说能够给我一个patch让我在多显示器下切换使用guake,那个patch如下:

--- /usr/bin/guake.bak	2013-05-27 14:29:48.589649485 +0800
+++ /usr/bin/guake	2013-05-27 15:00:05.067180502 +0800
@@ -844,7 +844,8 @@
         # get the rectangle just from the first/default monitor in the
         # future we might create a field to select which monitor you
         # wanna use
-        window_rect = screen.get_monitor_geometry(0)
+        current_monitor = screen.get_current_monitor()
+        window_rect = screen.get_monitor_geometry(current_monitor)
         total_width = window_rect.width
         window_rect.height = window_rect.height * height / 100
         window_rect.width = window_rect.width * width / 100

 

很显然他是将固定的使用monitor 0改成先获取current monitor然后再根据current的情况来变换。我欣然的接受了他的patch,并把补丁打到自己的系统上,但是我发现没有起作用。

由于他使用的是fedora20,我使用的是fedora19。我怀疑是gtk版本的问题导致工作不如意,于是我使用fedup将我的fedora19更新到20。


这回起作用了,果然鼠标在哪就可以把guake终端调到哪里。但是当我使用Alt+Tab切换的时候,再用F12就无法正常的切换到guake,它总是不停的闪烁,工作非常不正常。于是我查看了日志文件,发现这样的错误:

 gnome-session[1608]: File "/usr/bin/guake", line 198, in size_changed
gnome-session[1608]: window_rect = self.guake.get_final_window_rect()
gnome-session[1608]: File "/usr/bin/guake", line 846, in get_final_window_rect
gnome-session[1608]: current_monitor = screen.get_current_monitor()
gnome-session[1608]: AttributeError: 'gtk.gdk.ScreenX11' object has no attribute 'get_current_monitor'

 

也就是说我使用的gtk版本screen类已经不支持get_current_monitor方法了。于是我尝试自己写完成get_current_monitor操作,然后再使用得到的current_monitor,patch如下:

-        window_rect = screen.get_monitor_geometry(0)
+       #current_monitor = screen.get_current_monitor()
+       display = screen.get_display()
+       current_monitor = screen.get_monitor_at_point(*display.get_pointer()[1:3])
+        window_rect = screen.get_monitor_geometry(current_monitor)

 

这样一来get current monitor就完成了,使用起来不报错了,但是不能达到切换monitor的效果。于是我开始怀疑最开始那个get_current_monitor()的解决办法。它在fedora19上工作不能工作但是也不报错,就像现在这个patch。而在fedora20上就能达到效果,但存在bug。而且get_current_monitor方法都没有了,那个补丁是怎么在我同事的机器上工作的?


我不得其解,只能想到可能是错误成就了一个难以预知的效果。就像我们想把语言环境从汉语切换成英语,一般写LANG=C,但是如果你写LANG=c也行。但是实际上后一种是错误的写发,它把LANG环境变量设置成一个错误的状态,然后由于系统识别出了这个错误才默认把LANG设置成C状态。等于说是用错误来引出想要的效果,但是这是不正确不稳定的。


于是我开始研究pygtk的部分内容,想把目前这个问题解决了。终于功夫不负有心人,让我调试出了自己想要的效果,patch如下:

    --- guake.bk    2013-09-30 18:34:11.000000000 +0800
    +++ guake       2014-06-24 15:38:30.959716429 +0800
    @@ -843,19 +843,24 @@ class Guake(SimpleGladeApp):
             # get the rectangle just from the first/default monitor in the
             # future we might create a field to select which monitor you
             # wanna use
    -        window_rect = screen.get_monitor_geometry(0)
    +       #current_monitor = screen.get_current_monitor()
    +       display = screen.get_display()
    +       current_monitor = screen.get_monitor_at_point(*display.get_pointer()[1:3])
    +        monitor_rect = screen.get_monitor_geometry(current_monitor)
    +       window_rect = monitor_rect.copy()
    +
             total_width = window_rect.width
             window_rect.height = window_rect.height * height / 100
             window_rect.width = window_rect.width * width / 100
     
             if width < total_width:
                 if halignment == ALIGN_CENTER:
    -                window_rect.x = (total_width - window_rect.width) / 2
    +                window_rect.x = monitor_rect.x + (total_width - window_rect.width) / 2
                 elif halignment == ALIGN_LEFT:
    -                window_rect.x = 0
    +                window_rect.x = monitor_rect.x
                 elif halignment == ALIGN_RIGHT:
    -                window_rect.x = total_width - window_rect.width
    -        window_rect.y = 0
    +                window_rect.x = monitor_rect.x + total_width - window_rect.width
    +        window_rect.y = monitor_rect.y
             return window_rect
     
         def get_running_fg_processes(self):

 

很明显,在获得了current monitor之后应该更新window的坐标信息,这样才能让guake正确的切换到想要的位置。


由于是我个人使用,所以以上的patch没有经过过多的测试和验证,可能在一些情况下还存在问题。如果有人发现问题并提出更好的修正补丁,希望能告诉我。


最后我想说,解决问题的方式有很多,但是不是问题不见了就算解决了。很有可能是你引入了更复杂的问题把当前的问题掩盖了。所以,尽力去找到正确有效的解决途径才是上上之策,不要让错误来掩盖错误。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值