refactorize get_server_time

should fix crash on Wayland

Ref: #1071

Signed-off-by: Gaetan Semet <gaetan@xeberon.net>
This commit is contained in:
Gaetan Semet 2018-01-15 14:10:18 +01:00
parent 4b50f6714f
commit cf052b6077
3 changed files with 42 additions and 16 deletions

View File

@ -68,6 +68,7 @@ from guake.settings import Settings
from guake.simplegladeapp import SimpleGladeApp
from guake.simplegladeapp import bindtextdomain
from guake.terminal import GuakeTerminalBox
from guake.utils import get_server_time
libutempter = None
try:
@ -610,7 +611,7 @@ class Guake(SimpleGladeApp):
value = self.settings.general.get_boolean('window-losefocus')
visible = window.get_property('visible')
if visible:
self.losefocus_time = GdkX11.x11_get_server_time(self.window.get_window())
self.losefocus_time = get_server_time(self.window)
if value:
self.hide()
@ -862,16 +863,9 @@ class Guake(SimpleGladeApp):
if not self.is_fullscreen:
self.settings.general.triggerOnChangedValue(self.settings.general, 'window-height')
try:
# does it work in other gtk backends
# help(self.window.get_window())
time = GdkX11.x11_get_server_time(self.window.get_window())
except (TypeError, AttributeError):
# Issue: https://github.com/Guake/guake/issues/1071
# Wayland does not seem to like `x11_get_server_time`.
# Quick and dirty fix like https://launchpadlibrarian.net/309178299/wayland_fix.diff
time = 0
# TODO PORT this
time = get_server_time(self.window)
# TODO PORT this
# When minized, the window manager seems to refuse to resume
# log.debug("self.window: %s. Dir=%s", type(self.window), dir(self.window))
# is_iconified = self.is_iconified()
@ -1984,10 +1978,7 @@ class Guake(SimpleGladeApp):
search_query = quote_plus(search_query)
if search_query:
search_url = "https://www.google.com/#q={!s}&safe=off".format(search_query, )
Gtk.show_uri(
self.window.get_screen(), search_url,
GdkX11.x11_get_server_time(self.window.get_window())
)
Gtk.show_uri(self.window.get_screen(), search_url, get_server_time(self.window))
return True
def getCurrentTerminalLinkUnderCursor(self):

View File

@ -144,7 +144,7 @@ class Terminal(Vte.Terminal):
elif TERMINAL_MATCH_TAGS[tag] == 'email':
value = 'mailto:%s' % value
Gtk.show_uri(self.get_screen(), value, GdkX11.x11_get_server_time(self.get_window()))
Gtk.show_uri(self.get_screen(), value, get_server_time(self))
elif event.button == 3 and matched_string:
self.matched_value = matched_string[0]

35
guake/utils.py Normal file
View File

@ -0,0 +1,35 @@
# -*- coding: utf-8; -*-
"""
Copyright (C) 2007-2012 Lincoln de Sousa <lincoln@minaslivre.org>
Copyright (C) 2007 Gabriel Falcão <gabrielteratos@gmail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public
License along with this program; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
"""
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import GdkX11
def get_server_time(widget):
try:
return GdkX11.x11_get_server_time(widget.get_window())
except (TypeError, AttributeError):
# Issue: https://github.com/Guake/guake/issues/1071
# Wayland does not seem to like `x11_get_server_time`.
# Quick and dirty fix like https://launchpadlibrarian.net/309178299/wayland_fix.diff
return 0