def layout_done(self): """Layout operations have finished, record that fact""" self.doing_layout = False maker = Factory() window_last_active_term_mapping = {} for window in self.windows: if window.is_child_notebook(): source = window.get_toplevel().get_children()[0] else: source = window window_last_active_term_mapping[window] = copy.copy( source.last_active_term) for terminal in self.terminals: if not terminal.pid: terminal.spawn_child() for window in self.windows: if not window.is_child_notebook(): # For windows without a notebook ensure Terminal is visible and focussed if window_last_active_term_mapping[window]: term = self.find_terminal_by_uuid( window_last_active_term_mapping[window].urn) term.ensure_visible_and_focussed() # Build list of new windows using prelayout list new_win_list = [] if self.prelayout_windows: for window in self.windows: if window not in self.prelayout_windows: new_win_list.append(window) # Make sure all new windows get bumped to the top for window in new_win_list: window.show() window.grab_focus() try: t = GdkX11.x11_get_server_time(window.get_window()) except (NameError, TypeError, AttributeError): t = 0 window.get_window().focus(t) # Awful workaround to be sure that the last focused window is actually the one focused. # Don't ask, don't tell policy on this. Even this is not 100% if self.last_active_window: window = self.find_window_by_uuid(self.last_active_window.urn) count = 0 while count < 1000 and Gtk.events_pending(): count += 1 Gtk.main_iteration_do(False) window.show() window.grab_focus() try: t = GdkX11.x11_get_server_time(window.get_window()) except (NameError, TypeError, AttributeError): t = 0 window.get_window().focus(t) self.prelayout_windows = None
def update_labels(self): """ Updates keyboard labels based on active X keymap """ labels = {} # Get current layout group dpy = X.Display(hash( GdkX11.x11_get_default_xdisplay())) # Still no idea why... group = X.get_xkb_state(dpy).group # Get state of shift/alt/ctrl key mt = Gdk.ModifierType(self.keymap.get_modifier_state()) for a in self.background.areas: # Iterate over all translatable keys... if hasattr(Keys, a.name) and getattr(Keys, a.name) in KEY_TO_GDK: # Try to convert GKD key to keycode gdkkey = KEY_TO_GDK[getattr(Keys, a.name)] found, entries = self.keymap.get_entries_for_keyval(gdkkey) if gdkkey == Gdk.KEY_equal: # Special case, GDK reports nonsense here entries = [[e for e in entries if e.level == 0][-1]] if not found: continue for k in sorted(entries, key=lambda a: a.level): # Try to convert keycode to label translation = self.keymap.translate_keyboard_state( k.keycode, mt, group) if hasattr(translation, "keyval"): code = Gdk.keyval_to_unicode(translation.keyval) else: code = Gdk.keyval_to_unicode(translation[1]) if code != 0: labels[a.name] = unichr(code) break self.background.set_labels(labels)
def __init__(self): GObject.GObject.__init__(self) self.name = "JAMediaVideoDesktop" self.pipeline = False self.bus = False self.info = False #self.resolucion = "video/x-raw-yuv,width=640,height=480" # 800x600 no menor a 640x480 self.audio_enabled = True self.actualizador = False self.file_path = False self.ximagesrc = False self.videoconvert = False self.videoscale = False self.video_capsfilter = False self.theoraenc = False self.gconfaudiosrc = False self.audiorate = False self.audio_capsfilter = False self.audioconvert = False self.vorbisenc = False self.hilovideomuxor = False self.hiloaudiomuxor = False self.oggmux = False self.filesink = False self.screen = GdkX11.X11Screen() self.x = 0 self.y = 0 self.width = int(self.screen.width()) self.height = int(self.screen.height())
def activate(self): if not getattr(self, 'window', None): return self.window.activate(GdkX11.x11_get_server_time(self.x11window)) self.window.set_skip_tasklist(False) self.window.set_skip_pager(False) self.window.make_above()
def make_hole(self, border_width): """ Uses shape extension to create hole in window... Area needs only border, rest should be transparent. """ width, height = self.size dpy = X.Display(hash(GdkX11.x11_get_default_xdisplay()) ) # I have no idea why this works... wid = X.XID(self.get_window().get_xid()) mask = X.create_pixmap(dpy, wid, width, height, 1) xgcv = X.c_void_p() gc = X.create_gc(dpy, mask, 0, xgcv) X.set_foreground(dpy, gc, 1) X.fill_rectangle(dpy, mask, gc, 0, 0, width, height) X.set_foreground(dpy, gc, 0) X.fill_rectangle(dpy, mask, gc, border_width, border_width, width - 2 * border_width, height - 2 * border_width) SHAPE_BOUNDING = 0 SHAPE_SET = 0 X.shape_combine_mask(dpy, wid, SHAPE_BOUNDING, 0, 0, mask, SHAPE_SET) X.free_gc(dpy, gc) X.free_pixmap(dpy, mask)
def __fill_layouts_dict(): """assemble dictionary of layout codes to corresponding layout name """ _xkl_engine = Xkl.Engine.get_instance(GdkX11.x11_get_default_xdisplay()) _xkl_registry = Xkl.ConfigRegistry.get_instance(_xkl_engine) _xkl_registry.load(False) layouts_dict = {} def variant_iter(registry, variant, layout): code = '%s/%s' % (xkl_strip(layout.name), xkl_strip(variant.name)) description = '%s - %s' % (xkl_strip(layout.description), xkl_strip(variant.description)) if code not in layouts_dict: layouts_dict[code] = description def layout_iter(registry, layout, _): code = xkl_strip(layout.name) description = xkl_strip(layout.description) if code not in layouts_dict: layouts_dict[code] = description _xkl_registry.foreach_layout_variant(code, variant_iter, layout) _xkl_registry.foreach_layout(layout_iter, None) return layouts_dict
def make_window_clicktrough(self): dpy = X.Display(hash(GdkX11.x11_get_default_xdisplay())) # I have no idea why this works... win = X.XID(self.get_window().get_xid()) reg = X.create_region(dpy, None, 0) X.set_window_shape_region (dpy, win, X.SHAPE_BOUNDING, 0, 0, 0) X.set_window_shape_region (dpy, win, X.SHAPE_INPUT, 0, 0, reg) X.destroy_region (dpy, reg)
def make_hole(self, border_width): """ Uses shape extension to create hole in window... Area needs only border, rest should be transparent. """ width, height = self.size dpy = X.Display(hash(GdkX11.x11_get_default_xdisplay())) # I have no idea why this works... wid = X.XID(self.get_window().get_xid()) mask = X.create_pixmap(dpy, wid, width, height, 1) xgcv = X.c_void_p() gc = X.create_gc(dpy, mask, 0, xgcv) X.set_foreground(dpy, gc, 1) X.fill_rectangle(dpy, mask, gc, 0, 0, width, height) X.set_foreground(dpy, gc, 0) X.fill_rectangle(dpy, mask, gc, border_width, border_width, width - 2 * border_width, height - 2 * border_width) SHAPE_BOUNDING = 0 SHAPE_SET = 0 X.shape_combine_mask(dpy, wid, SHAPE_BOUNDING, 0, 0, mask, SHAPE_SET) X.free_gc(dpy, gc) X.free_pixmap(dpy, mask)
def get_timestamp(self): """Returns the timestamp for the windowing server.""" timestamp = 0 gdk_window = self.window.get_window() if GdkX11 and isinstance(gdk_window, GdkX11.X11Window): timestamp = GdkX11.x11_get_server_time(gdk_window) return timestamp
def getXTime(self): try: time = GdkX11.x11_get_server_time(self.get_window()) except: time = 0 return time
def __init__(self, cls="osd-menu"): OSDWindow.__init__(self, cls) self.daemon = None self.config = None self.feedback = None self.controller = None self.xdisplay = X.Display(hash(GdkX11.x11_get_default_xdisplay())) # Magic cursor = os.path.join(get_share_path(), "images", 'menu-cursor.svg') self.cursor = Gtk.Image.new_from_file(cursor) self.cursor.set_name("osd-menu-cursor") self.parent = self.create_parent() self.f = Gtk.Fixed() self.f.add(self.parent) self.add(self.f) self._submenu = None self._scon = StickController() self._scon.connect("direction", self.on_stick_direction) self._is_submenu = False self._selected = None self._menuid = None self._use_cursor = False self._eh_ids = [] self._control_with = STICK self._control_with_dpad = False self._confirm_with = 'A' self._cancel_with = 'B'
def button_press(self, terminal, event): """Handles the button press event in the terminal widget. If any match string is caught, another aplication is open to handle the matched resource uri. """ self.matched_value = '' matched_string = self.match_check( int(event.x / self.get_char_width()), int(event.y / self.get_char_height())) value, tag = matched_string if event.button == 1 \ and event.get_state() & Gdk.ModifierType.CONTROL_MASK \ and value: if TERMINAL_MATCH_TAGS[tag] == 'schema': # value here should not be changed, it is right and # ready to be used. pass elif TERMINAL_MATCH_TAGS[tag] == 'http': value = 'http://%s' % value elif TERMINAL_MATCH_TAGS[tag] == 'https': value = 'https://%s' % value elif TERMINAL_MATCH_TAGS[tag] == 'ftp': value = 'ftp://%s' % value 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())) elif event.button == 3 and matched_string: self.matched_value = matched_string[0]
def button_press(self, terminal, event): """Handles the button press event in the terminal widget. If any match string is caught, another aplication is open to handle the matched resource uri. """ self.matched_value = '' matched_string = self.match_check( int(event.x / self.get_char_width()), int(event.y / self.get_char_height())) value, tag = matched_string if event.button == 1 \ and event.get_state() & Gdk.ModifierType.CONTROL_MASK \ and value: if TERMINAL_MATCH_TAGS[tag] == 'schema': # value here should not be changed, it is right and # ready to be used. pass elif TERMINAL_MATCH_TAGS[tag] == 'http': value = 'http://%s' % value 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())) elif event.button == 3 and matched_string: self.matched_value = matched_string[0]
def __init__(self, cls="osd-menu"): OSDWindow.__init__(self, cls) self.daemon = None self.config = None self.xdisplay = X.Display(hash( GdkX11.x11_get_default_xdisplay())) # Magic cursor = os.path.join(get_share_path(), "images", 'menu-cursor.svg') self.cursor = Gtk.Image.new_from_file(cursor) self.cursor.set_name("osd-menu-cursor") self.parent = self.create_parent() self.f = Gtk.Fixed() self.f.add(self.parent) self.add(self.f) self._submenu = None self._scon = StickController() self._scon.connect("direction", self.on_stick_direction) self._is_submenu = False self._selected = None self._menuid = None self._use_cursor = False self._eh_ids = [] self._control_with = STICK self._confirm_with = 'A' self._cancel_with = 'B'
def update_labels(self): """ Updates keyboard labels based on active X keymap """ labels = {} # Get current layout group dpy = X.Display(hash(GdkX11.x11_get_default_xdisplay())) # Still no idea why... group = X.get_xkb_state(dpy).group # Get state of shift/alt/ctrl key mt = Gdk.ModifierType(self.keymap.get_modifier_state()) for a in self.background.areas: # Iterate over all translatable keys... if hasattr(Keys, a.name) and getattr(Keys, a.name) in KEY_TO_GDK: # Try to convert GKD key to keycode gdkkey = KEY_TO_GDK[getattr(Keys, a.name)] found, entries = self.keymap.get_entries_for_keyval(gdkkey) if gdkkey == Gdk.KEY_equal: # Special case, GDK reports nonsense here entries = [ [ e for e in entries if e.level == 0 ][-1] ] if not found: continue for k in sorted(entries, key=lambda a : a.level): # Try to convert keycode to label code = Gdk.keyval_to_unicode( self.keymap.translate_keyboard_state(k.keycode, mt, group) .keyval) if code != 0: labels[a.name] = unichr(code) break self.background.set_labels(labels)
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`. # Use local timestamp instead return get_local_timestamp()
def __map_event_cb(self, window, event): # have to make the desktop window active # since metacity doesn't make it on startup timestamp = event.get_time() x11_window = self.get_window() if not timestamp: timestamp = GdkX11.x11_get_server_time(x11_window) x11_window.focus(timestamp)
def activate(window): workspace = window.get_workspace() now = GdkX11.x11_get_server_time(Gdk.get_default_root_window()) if workspace is not None: # We need to first activate the workspace, otherwise windows on a different workspace might not become visible workspace.activate(now) window.activate(now)
def _make_window_clicktrough(self): """Make events pass through window.""" dpy = X.Display(hash(GdkX11.x11_get_default_xdisplay())) win = X.XID(self.get_window().get_xid()) reg = X.create_region(dpy, None, 0) X.set_window_shape_region(dpy, win, X.SHAPE_BOUNDING, 0, 0, 0) X.set_window_shape_region(dpy, win, X.SHAPE_INPUT, 0, 0, reg) X.destroy_region(dpy, reg)
def run(self, window, screen): if self.arg: if not window.is_minimized(): window.minimize() else: if window.is_minimized(): gdk_window = get_gdk_window(window) window.unminimize(GdkX11.x11_get_server_time(gdk_window))
def activate_window(window): screen = Wnck.Screen.get_default() screen.force_update() wnckwin = [ win for win in screen.get_windows() if win.get_xid() == window.get_xid() ][0] wnckwin.activate(GdkX11.x11_get_server_time(window))
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
def main(): #atom = Gdk.Atom.intern("CLIPBOARD", False) #clippy = Gtk.Clipboard.get(selection=atom) clippy = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) result, targets = clippy.wait_for_targets() for target in targets: print target, GdkX11.x11_xatom_to_atom(target).name() print(targets)
def main(argv): # No arg list, pass out help if len(argv) == 0: printHelp() sys.exit(2) buff = 20 try: opts, args = getopt.getopt(argv,"hudlrb:v") except getopt.GetoptError as err: printHelp() sys.exit(2) direction = "" verbose = False for opt, arg in opts: if opt == "-h": printHelp() sys.exit() elif opt == "-u": direction = "UP" elif opt == "-d": direction = "DOWN" elif opt == "-l": direction = "LEFT" elif opt == "-r": direction = "RIGHT" elif opt == "-b": buff = int(arg) elif opt == "-v": verbose = True # Grab window list and geo Gtk.init([]) # necessary if not using a Gtk.main() loop screen = Wnck.Screen.get_default() screen.force_update() # recommended per Wnck documentation window_list = screen.get_windows() active_window = screen.get_active_window() workspace_id = screen.get_active_workspace().get_number() if len(window_list) > 0: window = findWindow( direction, window_list, workspace_id, active_window, buff, verbose ) else: print( "Empty window list!" ) sys.exit(2) if window != None: now = GdkX11.x11_get_server_time(Gdk.get_default_root_window()) window.activate(now) window = None screen = None Wnck.shutdown()
def __init__(self): """ Init dbus objects """ # Just to make pep8/flake8 happy GdkX11.x11_get_default_root_xwindow() # Dbus interface to disable screenlock bus = dbus.SessionBus() self._sm = None self._cookie = None self._flags = [] try: bus_object = bus.get_object('org.gnome.SessionManager', '/org/gnome/SessionManager') self._sm = dbus.Interface(bus_object, 'org.gnome.SessionManager') except: self._sm = None Lp().player.connect('status-changed', self._on_status_changed)
def __init__(self): # pylint: disable-msg=E0611 from gi.repository import GdkX11 #initialize Xkl-related stuff display = GdkX11.x11_get_default_xdisplay() self._engine = Xkl.Engine.get_instance(display) self._rec = Xkl.ConfigRec() if not self._rec.get_from_server(self._engine): raise XklWrapperError("Failed to get configuration from server") #X is probably initialized to the 'us' layout without any variant and #since we want to add layouts with variants we need the layouts and #variants lists to have the same length. Add "" padding to variants. #See docstring of the add_layout method for details. diff = len(self._rec.layouts) - len(self._rec.variants) if diff > 0 and flags.can_touch_runtime_system("activate layouts"): self._rec.set_variants(self._rec.variants + (diff * [""])) if not self._rec.activate(self._engine): # failed to activate layouts given e.g. by a kickstart (may be # invalid) lay_var_str = ",".join(map(_join_layout_variant, self._rec.layouts, self._rec.variants)) log.error("Failed to activate layouts: '%s', " "falling back to default 'us'" % lay_var_str) self._rec.set_layouts(["us"]) self._rec.set_variants([""]) if not self._rec.activate(self._engine): # failed to activate even the default "us" layout, something # is really wrong raise XklWrapperError("Failed to initialize layouts") #needed also for Gkbd.KeyboardDrawingDialog self.configreg = Xkl.ConfigRegistry.get_instance(self._engine) self.configreg.load(False) self._language_keyboard_variants = dict() self._country_keyboard_variants = dict() self._switching_options = list() #we want to display layouts as 'language (description)' self.name_to_show_str = dict() #we want to display layout switching options as e.g. "Alt + Shift" not #as "grp:alt_shift_toggle" self.switch_to_show_str = dict() #this might take quite a long time self.configreg.foreach_language(self._get_language_variants, None) self.configreg.foreach_country(self._get_country_variants, None) #'grp' means that we want layout (group) switching options self.configreg.foreach_option('grp', self._get_switch_option, None)
def setup(): if not _USE_XKL: return gconf_client = GConf.Client.get_default() have_config = False try: display = GdkX11.x11_get_default_xdisplay() if display is not None: engine = Xkl.Engine.get_instance(display) else: logging.debug('setup_keyboard_cb: Could not get default display.') return configrec = Xkl.ConfigRec() configrec.get_from_server(engine) # FIXME, gconf_client_get_list not introspectable #681433 layouts_from_gconf = gconf_client.get( '/desktop/sugar/peripherals/keyboard/layouts') layouts_list = [] variants_list = [] if layouts_from_gconf: for gval in layouts_from_gconf.get_list(): layout = gval.get_string() layouts_list.append(layout.split('(')[0]) variants_list.append(layout.split('(')[1][:-1]) if layouts_list and variants_list: have_config = True configrec.set_layouts(layouts_list) configrec.set_variants(variants_list) model = gconf_client.get_string(\ '/desktop/sugar/peripherals/keyboard/model') if model: have_config = True configrec.set_model(model) options = [] # FIXME, gconf_client_get_list not introspectable #681433 options_from_gconf = gconf_client.get(\ '/desktop/sugar/peripherals/keyboard/options') if options_from_gconf: for gval in options_from_gconf.get_list(): option = gval.get_string() options.append(option) if options: have_config = True configrec.set_options(options) if have_config: configrec.activate(engine) except Exception: logging.exception('Error during keyboard configuration')
def present_window(window: Gtk.Window): if window.is_active(): return timestamp = Gtk.get_current_event_time() if timestamp == 0: from gi.repository import GdkX11 timestamp = GdkX11.x11_get_server_time(window.get_window()) window.present_with_time(timestamp)
def move_keyboard(self, window): GdkX11.x11_grab_server() old_window = self.keyboard_grab_window if old_window: self.release_keyboard() res = self.grab_keyboard(window) if not res: time.sleep(1) res = self.grab_keyboard(window) if not res and old_window: self.grab_keyboard(old_window) GdkX11.x11_ungrab_server() return res
def move_mouse(self, window, hide_cursor): GdkX11.x11_grab_server() old_window = self.mouse_grab_window if old_window: self.release_mouse() res = self.grab_mouse(window, hide_cursor) if not res: time.sleep(1) res = self.grab_mouse(window, hide_cursor) if not res and old_window: self.grab_mouse(old_window) GdkX11.x11_ungrab_server() return res
def run(self, window, screen): space = screen.get_workspace(self.arg) if space: active_space = screen.get_active_workspace() if active_space and space == active_space: return # Delay workspace switch or some window managers have display issues gdk_window = get_gdk_window(window) timestamp = GdkX11.x11_get_server_time(gdk_window) GLib.timeout_add(100, self._delayed_activate_workspace, space, timestamp)
def open(self, app): try: from ._xsmp import XSMPClient, XSMPError except ImportError as e: raise SessionError(e) print_d("Connecting with XSMP") client = XSMPClient() try: client.open() except XSMPError as e: raise SessionError(e) try: from gi.repository import GdkX11 except ImportError: pass else: GdkX11.x11_set_sm_client_id(client.client_id) print_d("Connected. Client ID: %s" % client.client_id) def save_yourself(client, *args): print_d("xsmp: save_yourself %r" % (args, )) client.save_yourself_done(True) def die(client, *args): print_d("xsmp: die") app.quit() def save_complete(client): print_d("xsmp: save_complete") def shutdown_cancelled(client): print_d("xsmp: shutdown_cancelled") client.connect("save-yourself", save_yourself) client.connect("die", die) client.connect("save-complete", save_complete) client.connect("shutdown-cancelled", shutdown_cancelled) self._client = client
def open(self, app): try: from ._xsmp import XSMPClient, XSMPError except ImportError as e: raise SessionError(e) print_d("Connecting with XSMP") client = XSMPClient() try: client.open() except XSMPError as e: raise SessionError(e) try: from gi.repository import GdkX11 except ImportError: pass else: GdkX11.x11_set_sm_client_id(client.client_id) print_d("Connected. Client ID: %s" % client.client_id) def save_yourself(client, *args): print_d("xsmp: save_yourself %r" % (args,)) client.save_yourself_done(True) def die(client, *args): print_d("xsmp: die") app.quit() def save_complete(client): print_d("xsmp: save_complete") def shutdown_cancelled(client): print_d("xsmp: shutdown_cancelled") client.connect("save-yourself", save_yourself) client.connect("die", die) client.connect("save-complete", save_complete) client.connect("shutdown-cancelled", shutdown_cancelled) self._client = client
def _make_window_clickthrough(self): """Make events pass through window.""" dpy = X.Display(hash(GdkX11.x11_get_default_xdisplay())) try: xid = self.get_window().get_xid() except AttributeError: # Probably on Wayland return win = X.XID(xid) reg = X.create_region(dpy, None, 0) X.set_window_shape_region(dpy, win, X.SHAPE_BOUNDING, 0, 0, 0) X.set_window_shape_region(dpy, win, X.SHAPE_INPUT, 0, 0, reg) X.destroy_region(dpy, reg)
def _activateCb(self, unused_app): if self.gui: # The app is already started and the window already created. # Present the already existing window. # TODO: Use present() instead of present_with_time() when # https://bugzilla.gnome.org/show_bug.cgi?id=688830 is fixed. x11_server_time = GdkX11.x11_get_server_time(self.gui.get_window()) self.gui.present_with_time(x11_server_time) # No need to show the welcome wizard. return self.createMainWindow() self.welcome_wizard = StartUpWizard(self) self.welcome_wizard.show()
def __init__(self): from gi.repository import GdkX11, Xkl self._xkl = Xkl #initialize Xkl-related stuff display = GdkX11.x11_get_default_xdisplay() self._engine = Xkl.Engine.get_instance(display) self._rec = Xkl.ConfigRec() if not self._rec.get_from_server(self._engine): raise XklWrapperError("Failed to get configuration from server") #X is probably initialized to the 'us' layout without any variant and #since we want to add layouts with variants we need the layouts and #variants lists to have the same length. Add "" padding to variants. #See docstring of the add_layout method for details. diff = len(self._rec.layouts) - len(self._rec.variants) if diff > 0 and flags.can_touch_runtime_system("activate layouts"): self._rec.set_variants(self._rec.variants + (diff * [""])) if not self._rec.activate(self._engine): # failed to activate layouts given e.g. by a kickstart (may be # invalid) lay_var_str = ",".join( map(_join_layout_variant, self._rec.layouts, self._rec.variants)) log.error( "Failed to activate layouts: '%s', " "falling back to default %s", lay_var_str, DEFAULT_KEYBOARD) self._rec.set_layouts([DEFAULT_KEYBOARD]) self._rec.set_variants([""]) if not self._rec.activate(self._engine): # failed to activate even the default layout, something is # really wrong raise XklWrapperError("Failed to initialize layouts") #needed also for Gkbd.KeyboardDrawingDialog self.configreg = Xkl.ConfigRegistry.get_instance(self._engine) self.configreg.load(False) self._layout_infos = dict() self._switch_opt_infos = dict() #this might take quite a long time self.configreg.foreach_language(self._get_language_variants, None) self.configreg.foreach_country(self._get_country_variants, None) #'grp' means that we want layout (group) switching options self.configreg.foreach_option('grp', self._get_switch_option, None)
def on_window_losefocus(self, window, event): if self.slide_effect_running: return if ConfigManager.disable_losefocus_temporary: return if not ConfigManager.get_conf('losefocus-hiding'): return if self.get_property('visible'): self.losefocus_time = GdkX11.x11_get_server_time(self.get_window()) if ConfigManager.get_conf('use-animation'): self.slide_up() self.unrealize() self.hide()
def generate(self, menuhandler): rv = [] dpy = X.Display(hash(GdkX11.x11_get_default_xdisplay())) # Magic root = X.get_default_root_window(dpy) count, wlist = X.get_window_prop(dpy, root, "_NET_CLIENT_LIST", 1024) skip_taskbar = X.intern_atom(dpy, "_NET_WM_STATE_SKIP_TASKBAR", True) wlist = cast(wlist, POINTER(X.XID))[0:count] for win in wlist: if not skip_taskbar in X.get_wm_state(dpy, win): title = X.get_window_title(dpy, win)[0:self.MAX_LENGHT] menuitem = MenuItem(str(win), title) menuitem.callback = WindowListMenuGenerator.callback rv.append(menuitem) return rv
def reveal(self): """ Make window active In contrast with present(), brings window to the top even after invoking on response on non-gtk events. See #1423. """ window = self.get_window() if window is None: self.show() return timestamp = Gtk.get_current_event_time() if not timestamp: timestamp = GdkX11.x11_get_server_time(window) window.focus(timestamp)
def reveal(self): """ Make window active. Brings the window to the top and makes it active, even after invoking on response to non-GTK events (in contrast to present()). See bug #1423 """ window = self.get_window() if window is None: self.show() return timestamp = Gtk.get_current_event_time() if not timestamp: timestamp = GdkX11.x11_get_server_time(window) window.focus(timestamp)
def __init__(self): #initialize Xkl-related stuff display = GdkX11.x11_get_default_xdisplay() self._engine = Xkl.Engine.get_instance(display) self._rec = Xkl.ConfigRec() if not self._rec.get_from_server(self._engine): raise XklWrapperError("Failed to get configuration from server") #X is probably initialized to the 'us' layout without any variant and #since we want to add layouts with variants we need the layouts and #variants lists to have the same length. Add "" padding to variants. #See docstring of the add_layout method for details. diff = len(self._rec.layouts) - len(self._rec.variants) if diff > 0 and flags.can_touch_runtime_system("activate layouts"): self._rec.set_variants(self._rec.variants + (diff * [""])) if not self._rec.activate(self._engine): # failed to activate layouts given e.g. by a kickstart (may be # invalid) lay_var_str = ",".join(map(join_layout_variant, self._rec.layouts, self._rec.variants)) log.error("Failed to activate layouts: '%s', " "falling back to default %s", lay_var_str, DEFAULT_KEYBOARD) self._rec.set_layouts([DEFAULT_KEYBOARD]) self._rec.set_variants([""]) if not self._rec.activate(self._engine): # failed to activate even the default layout, something is # really wrong raise XklWrapperError("Failed to initialize layouts") #needed also for Gkbd.KeyboardDrawingDialog self.configreg = Xkl.ConfigRegistry.get_instance(self._engine) self.configreg.load(False) self._layout_infos = dict() self._layout_infos_lock = threading.RLock() self._switch_opt_infos = dict() self._switch_opt_infos_lock = threading.RLock() #this might take quite a long time self.configreg.foreach_language(self._get_language_variants, None) self.configreg.foreach_country(self._get_country_variants, None) #'grp' means that we want layout (group) switching options self.configreg.foreach_option('grp', self._get_switch_option, None)
def present(self): """A version of present that also works if not called from an event handler (there is no active input event). See https://bugzilla.gnome.org/show_bug.cgi?id=688830 """ try: from gi.repository import GdkX11 except ImportError: super(Window, self).present() else: window = self.get_window() if window and isinstance(window, GdkX11.X11Window): timestamp = GdkX11.x11_get_server_time(window) self.present_with_time(timestamp) else: super(Window, self).present()
def do_activate(self): if self.gui: # The app is already started and the window already created. # Present the already existing window. if self.system.has_x11(): # TODO: Use present() instead of present_with_time() when # https://bugzilla.gnome.org/show_bug.cgi?id=688830 is fixed. from gi.repository import GdkX11 x11_server_time = GdkX11.x11_get_server_time(self.gui.get_window()) self.gui.present_with_time(x11_server_time) else: # On Wayland or Quartz (Mac OS X) backend there is no GdkX11, # so just use present() directly here. self.gui.present() # No need to show the welcome wizard. return self.createMainWindow() self.welcome_wizard.show()
def __init__(self, model, alerts): SectionView.__init__(self) self._model = model self._kmodel = None self._selected_kmodel = None self._klayouts = [] self._selected_klayouts = [] self._group_switch_option = None self._selected_group_switch_option = None self.set_border_width(style.DEFAULT_SPACING * 2) self.set_spacing(style.DEFAULT_SPACING) self._layout_table = Gtk.Table(rows=4, columns=2, homogeneous=False) _build_ISO_639_dictionary() self._keyboard_manager = model.KeyboardManager( GdkX11.x11_get_default_xdisplay()) self._layout_combo_list = [] self._layout_addremovebox_list = [] scrollwindow = Gtk.ScrolledWindow() scrollwindow.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) self.pack_start(scrollwindow, True, True, 0) scrollwindow.show() self._vbox = Gtk.VBox() scrollwindow.add_with_viewport(self._vbox) self.__kmodel_sid = None self.__layout_sid = None self.__group_switch_sid = None self._setup_kmodel() self._setup_layouts() self._setup_group_switch_option() self._vbox.show()
def __init__(self, cls="osd-menu"): self._buttons = None self._string = "" OSDWindow.__init__(self, cls) self.daemon = None self.config = None self.feedback = None self.controller = None self.xdisplay = X.Display(hash(GdkX11.x11_get_default_xdisplay())) # Magic self.create_parent() self.create_app_list() self.create_buttons() cursor = os.path.join(get_share_path(), "images", 'menu-cursor.svg') self.cursors = [ Gtk.Image.new_from_file(cursor), Gtk.Image.new_from_file(cursor) ] for c in self.cursors: c.set_name("osd-menu-cursor") c.selected = None self.f.add(c) self.f.show_all() self._scon = StickController() self._scon.connect("direction", self.on_stick_direction) self._selected = None self._menuid = None self._eh_ids = [] self._confirm_with = 'A' self._cancel_with = 'B' if Launcher._app_db is None: Launcher._app_db = [] for x in Launcher.BUTTONS: for c in x: Launcher.CHAR_TO_NUMBER[c] = x[0] for x in Gio.AppInfo.get_all(): try: Launcher._app_db.append(( Launcher.name_to_keys(x), x )) except UnicodeDecodeError: # Just f**k them... pass
def setup(): settings = Gio.Settings('org.sugarlabs.peripherals.keyboard') have_config = False try: display = GdkX11.x11_get_default_xdisplay() if display is not None: engine = Xkl.Engine.get_instance(display) else: logging.debug('setup_keyboard_cb: Could not get default display.') return configrec = Xkl.ConfigRec() configrec.get_from_server(engine) layouts = settings.get_strv('layouts') layouts_list = [] variants_list = [] if layouts: for layout in layouts: layouts_list.append(layout.split('(')[0]) variants_list.append(layout.split('(')[1][:-1]) if layouts_list and variants_list: have_config = True configrec.set_layouts(layouts_list) configrec.set_variants(variants_list) model = settings.get_string('model') if model: have_config = True configrec.set_model(model) options = settings.get_strv('options') if options: have_config = True configrec.set_options(options) if have_config: configrec.activate(engine) except Exception: logging.exception('Error during keyboard configuration')
def __init__(self, cls="osd-menu"): self._buttons = None self._text = None OSDWindow.__init__(self, cls) self.daemon = None self.config = None self.feedback = None self.controller = None self.xdisplay = X.Display(hash(GdkX11.x11_get_default_xdisplay())) # Magic self.parent = self.create_parent() self.f = Gtk.Fixed() self.f.add(self.parent) self.add(self.f) self._scon = StickController() self._scon.connect("direction", self.on_stick_direction) self._selected = None self._eh_ids = []
def on_hide_window(self, data=None): """Handle a request to hide/show the window""" if not self.get_property('visible'): #Don't show if window has just been hidden because of #lost focus if (time.time() - self.losefocus_time < 0.1) and \ self.config['hide_on_lose_focus']: return if self.position: self.move(self.position[0], self.position[1]) self.show() self.grab_focus() try: t = GdkX11.x11_get_server_time(self.get_window()) except (TypeError, AttributeError): t = 0 self.get_window().focus(t) else: self.position = self.get_position() self.hidefunc()