diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-07-24 19:58:27 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-07-24 19:58:27 +0200 |
commit | 5ad5531baa3ab7729427caf821fde6a6856da34e (patch) | |
tree | 016644484b3c5814879a0e910394e9b064d2b2d2 /src/actionGroups/windowListGroup.vala | |
parent | 394ad3b32f9f79775bcac4c6cc2a4dfa74586800 (diff) | |
parent | 309d161f6d464fcea2de200bb3cb5a7cb784b6d3 (diff) |
Updated version 0.7.1 from 'upstream/0.7.1'
with Debian dir 55ec79e844cfb79babaf0535d64bfdb9bd5b22f7
Diffstat (limited to 'src/actionGroups/windowListGroup.vala')
-rw-r--r-- | src/actionGroups/windowListGroup.vala | 198 |
1 files changed, 111 insertions, 87 deletions
diff --git a/src/actionGroups/windowListGroup.vala b/src/actionGroups/windowListGroup.vala index c3560af..c572f75 100644 --- a/src/actionGroups/windowListGroup.vala +++ b/src/actionGroups/windowListGroup.vala @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// Copyright (c) 2011-2016 by Simon Schneegans +// Copyright (c) 2011-2017 by Simon Schneegans // // 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 @@ -29,7 +29,12 @@ public class WindowListGroup : ActionGroup { /// the pies.conf file for this kind of ActionGroups. ///////////////////////////////////////////////////////////////////// - public static GroupRegistry.TypeDescription register() { + public static GroupRegistry.TypeDescription? register() { + if (GLib.Environment.get_variable("XDG_SESSION_TYPE") == "wayland") { + warning("The WindowList slice group is not supported on Wayland."); + return null; + } + var description = new GroupRegistry.TypeDescription(); description.name = _("Group: Window List"); description.icon = "preferences-system-windows"; @@ -41,12 +46,14 @@ public class WindowListGroup : ActionGroup { public bool current_workspace_only { get; set; default=false; } ///////////////////////////////////////////////////////////////////// - /// Two members needed to avoid useless, frequent changes of the - /// stored Actions. + /// Cached icon names loaded from .desktop files. ///////////////////////////////////////////////////////////////////// - private bool changing = false; - private bool changed_again = false; + private static Gee.HashMap<string, string> cached_icon_name { private get; private set; } + + ///////////////////////////////////////////////////////////////////// + /// Wnck's Screen object, to control the list of opened windows. + ///////////////////////////////////////////////////////////////////// private Wnck.Screen screen; @@ -56,24 +63,22 @@ public class WindowListGroup : ActionGroup { public WindowListGroup(string parent_id) { GLib.Object(parent_id : parent_id); - } - ///////////////////////////////////////////////////////////////////// - /// Loads all windows. - ///////////////////////////////////////////////////////////////////// + screen = Wnck.Screen.get_default(); + WindowListGroup.cached_icon_name = new Gee.HashMap<string, string>(); - construct { - this.screen = Wnck.Screen.get_default(); + Gtk.IconTheme.get_default().changed.connect(() => { + WindowListGroup.cached_icon_name = new Gee.HashMap<string, string>(); + create_actions_for_all_windows(); + }); - this.screen.window_opened.connect(reload); - this.screen.window_closed.connect(reload); - this.screen.active_workspace_changed.connect(reload); - - this.update(); + screen.active_workspace_changed.connect(create_actions_for_all_windows); + screen.window_opened.connect(create_action); + screen.window_closed.connect(remove_action); } ///////////////////////////////////////////////////////////////////// - /// This one is called, when the ActionGroup is saved. + /// This one is called when the ActionGroup is saved. ///////////////////////////////////////////////////////////////////// public override void on_save(Xml.TextWriter writer) { @@ -82,7 +87,7 @@ public class WindowListGroup : ActionGroup { } ///////////////////////////////////////////////////////////////////// - /// This one is called, when the ActionGroup is loaded. + /// This one is called when the ActionGroup is loaded. ///////////////////////////////////////////////////////////////////// public override void on_load(Xml.Node* data) { @@ -91,98 +96,117 @@ public class WindowListGroup : ActionGroup { string attr_content = attribute->children->content; if (attr_name == "current_workspace_only") { - this.current_workspace_only = bool.parse(attr_content); + current_workspace_only = bool.parse(attr_content); } } } ///////////////////////////////////////////////////////////////////// - /// Loads all currently opened windows and creates actions for them. + /// Remove a Action for a given window ///////////////////////////////////////////////////////////////////// - private void update() { - unowned GLib.List<Wnck.Window?> windows = this.screen.get_windows(); - - foreach (var window in windows) { - if (window.get_window_type() == Wnck.WindowType.NORMAL - && !window.is_skip_pager() && !window.is_skip_tasklist() - && (!current_workspace_only || (window.get_workspace() != null - && window.get_workspace() == this.screen.get_active_workspace()))) { - - var application = window.get_application(); - var icon = application.get_icon_name().down(); - var name = window.get_name(); - - if (name.length > 30) { - name = name.substring(0, 30) + "..."; + private void remove_action(Wnck.Window window) { + if (!window.is_skip_pager() && !window.is_skip_tasklist()) + foreach (Action action in actions) + if (window.get_xid() == uint64.parse(action.real_command)) { + actions.remove(action); + break; } + } - var action = new SigAction(name, icon, "%lu".printf(window.get_xid())); + ///////////////////////////////////////////////////////////////////// + /// Create Action's for all currently opened windows. + ///////////////////////////////////////////////////////////////////// - action.activated.connect((time_stamp) => { - Wnck.Screen.get_default().force_update(); + private void create_actions_for_all_windows() { + delete_all(); - var xid = (X.Window)uint64.parse(action.real_command); - var win = Wnck.Window.get(xid); + foreach (var window in screen.get_windows()) + create_action(window); + } - if (win.get_workspace() != null) { - //select the workspace - if (win.get_workspace() != win.get_screen().get_active_workspace()) { - win.get_workspace().activate(time_stamp); - } + ///////////////////////////////////////////////////////////////////// + /// Create a Action for a given opened window + ///////////////////////////////////////////////////////////////////// - //select the viewport inside the workspace - if (!win.is_in_viewport(win.get_workspace()) ) { - int xp, yp, widthp, heightp, scx, scy, nx, ny, wx, wy; - win.get_geometry (out xp, out yp, out widthp, out heightp); - scx = win.get_screen().get_width(); - scy = win.get_screen().get_height(); - wx = win.get_workspace().get_viewport_x(); - wy = win.get_workspace().get_viewport_y(); - if (scx > 0 && scy > 0) { - nx= ((wx+xp) / scx) * scx; - ny= ((wy+yp) / scy) * scy; - win.get_screen().move_viewport(nx, ny); - } - } - } + private void create_action(Wnck.Window window) { + if (!window.is_skip_pager() && !window.is_skip_tasklist() + && (!current_workspace_only || (window.get_workspace() != null + && window.get_workspace() == screen.get_active_workspace()))) { - if (win.is_minimized()) { - win.unminimize(time_stamp); - } + var name = window.get_name(); + var icon_name = get_icon_name(window); + var xid = "%lu".printf(window.get_xid()); - win.activate_transient(time_stamp); - }); - this.add_action(action); + if (name.length > 30) { + name = name.substring(0, 30) + "..."; } - } - } - ///////////////////////////////////////////////////////////////////// - /// Reloads all running applications. - ///////////////////////////////////////////////////////////////////// + var action = new SigAction(name, icon_name, xid); + this.add_action(action); - private void reload() { - // avoid too frequent changes... - if (!this.changing) { - this.changing = true; - Timeout.add(500, () => { - if (this.changed_again) { - this.changed_again = false; - return true; + window.name_changed.connect(() => { + action.name = window.get_name(); + }); + + action.activated.connect((time_stamp) => { + if (window.get_workspace() != null) { + //select the workspace + if (window.get_workspace() != window.get_screen().get_active_workspace()) { + window.get_workspace().activate(time_stamp); + } } - // reload - this.delete_all(); - this.update(); + if (window.is_minimized()) { + window.unminimize(time_stamp); + } - this.changing = false; - return false; + window.activate_transient(time_stamp); }); - } else { - this.changed_again = true; } } + + private string get_icon_name(Wnck.Window window) { + string icon_name = ""; + + #if HAVE_BAMF + var xid = (uint32) window.get_xid(); + Bamf.Matcher bamf_matcher = Bamf.Matcher.get_default(); + Bamf.Application app = bamf_matcher.get_application_for_xid(xid); + string desktop_file = null; + + if (app != null) + desktop_file = app.get_desktop_file(); + + if (desktop_file != null) { + if (WindowListGroup.cached_icon_name.has_key(desktop_file)) + icon_name = WindowListGroup.cached_icon_name.get(desktop_file); + else { + try { + var file = new KeyFile(); + file.load_from_file(desktop_file, 0); + + if (file.has_key(KeyFileDesktop.GROUP, KeyFileDesktop.KEY_ICON)) { + icon_name = file.get_locale_string(KeyFileDesktop.GROUP, KeyFileDesktop.KEY_ICON); + WindowListGroup.cached_icon_name.set(desktop_file, icon_name); + } + } catch (GLib.KeyFileError e) { + error("%s", e.message); + } catch (GLib.FileError e) { + error("%s", e.message); + } + } + } else { + var application = window.get_application(); + icon_name = application.get_icon_name().down(); + } + #else + var application = window.get_application(); + icon_name = application.get_icon_name().down(); + #endif + + return icon_name; + } } } |