Thursday 20 September 2012

guake @Ubuntu 10.04 with two monitors

I love guake terminal on Ubuntu. However, it contains one flaw that is really painful having two monitors in a little less "standard" configuration.

I have a laptop and also use a larger external monitor in a configuration as below:


Guake terminal is designed to sit from the top of the screen, starting at the left border. 'Screen' is a keyword here, as the screen for those two monitors is a smallest rectangle containing both rectangles of those monitors. The effect is really astonishing:


(in fact, this is how Ubuntu sees my 'screen').

The problem has been already addressed here: http://www.dotmana.com/weblog/2011/02/guake-dual-screen-options/ and a patch has been issued: http://guake.org/ticket/201. However, it did not work for me. What I wanted to achieve is to have guake sitting on whichever monitor is placed higher (Samsung in this case).

I fixed it as follows:
petrelli@laps:~$ sudo gedit /usr/lib/guake/guake.py
Now look for function

def get_final_window_rect(self):
(it does guake windows positioning). This is the modified function body:

    def get_final_window_rect(self):
        """Gets the final size of the main window of guake. The height
        is the window_height property, width is window_width and the
        horizontal alignment is given by window_alignment.
        """
        screen = self.window.get_screen()
        height = self.client.get_int(KEY('/general/window_height'))
        halignment = self.client.get_int(KEY('/general/window_halignment'))

        # get the monitor that is placed higher and put guake on it
top_monitor = int(0)
monitors = int(screen.get_n_monitors())
for m in range(0, monitors):
window_rect = screen.get_monitor_geometry(m)
if(window_rect.y == 0):
top_monitor = m
break
        window_rect = screen.get_monitor_geometry(top_monitor)
        window_rect.height = window_rect.height * height / 100

        return window_rect

The result is following:

What is more, after disconnecting the external monitor, guake will appear properly on main monitor,  after reconnecting the external it will jump back where it is supposed to.

Cheers.

No comments: