1
/* Copyright 2010 Andrew Higginson
3
* This program is free software; you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation; either version 2 of the License, or
6
* (at your option) any later version.
9
public class WindowList : Gtk.HBox {
11
private Gtk.Builder builder;
12
private Wnck.Screen screen;
13
private Gee.ArrayList<Wnck.Window> windows = new Gee.ArrayList<Wnck.Window>();
16
this.homogeneous = true;
17
this.screen = Wnck.Screen.get_default();
18
this.screen.window_opened.connect(this.on_screen_window_opened);
19
this.screen.window_closed.connect(this.on_screen_window_closed);
20
this.screen.active_window_changed.connect(this.on_screen_active_window_changed);
23
/* Private Functions */
25
private WindowButton? get_button_for_window(Wnck.Window window) {
26
foreach (var widget in this.get_children()) {
27
var button = widget as WindowButton;
28
if (button.window == window) {
37
private void on_screen_window_opened(Wnck.Window window) {
38
this.windows.add(window);
40
if (window.is_skip_tasklist()) {
44
var button = new WindowButton(window);
45
button.window = window;
46
button.click_event.connect(this.on_window_button_click_event);
48
this.pack_start(button, true, true);
52
private void on_screen_window_closed(Wnck.Window window) {
53
this.windows.remove(window);
55
var button = this.get_button_for_window(window);
58
button.click_event.disconnect(this.on_window_button_click_event);
63
private void on_window_button_click_event(WindowButton button, Gdk.EventButton event) {
64
if (Gdk.ModifierType.BUTTON1_MASK in event.state) {
65
button.window.activate(event.time);
66
} else if (Gdk.ModifierType.BUTTON3_MASK in event.state) {
67
var menu = new WindowMenu(button);
68
menu.popup(null, null, null, event.button, event.time);
73
private void on_screen_active_window_changed(Wnck.Window? previous_active_window) {
74
if (previous_active_window != null) {
75
var button_previous_active = this.get_button_for_window(previous_active_window);
76
if (button_previous_active != null) {
77
button_previous_active.set_active(false);
81
var active_window = this.screen.get_active_window();
82
if (active_window != null) {
83
var button = this.get_button_for_window(active_window);
85
button.set_active(true);
90
/* Public Functions */
94
public class WindowButton : Gtk.ToggleButton {
96
public Wnck.Window window;
97
public QuickLists.QuickList quicklist;
98
private new bool pressed = false;
100
public new signal void click_event(Gdk.EventButton event);
102
public WindowButton(Wnck.Window window) {
103
this.window = window;
104
this.button_press_event.connect(this.on_button_press_event);
105
this.button_release_event.connect(this.on_button_release_event);
107
var hbox = new Gtk.HBox(false, 6);
108
var label = new Gtk.Label(window.get_name());
109
var pixbuf = window.get_mini_icon();
110
var image = new Gtk.Image.from_pixbuf(pixbuf);
112
label.set_ellipsize(Pango.EllipsizeMode.END);
113
label.set_alignment(0.0f, 0.5f);
115
hbox.pack_start(image, false, false);
116
hbox.pack_start(label, true, true);
121
this.quicklist = new QuickLists.QuickList.from_window(window);
124
private bool on_button_press_event(Gdk.EventButton event) {
129
private bool on_button_release_event(Gdk.EventButton event) {
131
this.click_event(event);
133
this.pressed = false;
138
public class WindowMenu : Gtk.Menu {
140
private QuickLists.QuickList quicklist;
141
private Wnck.Window window;
143
public WindowMenu(WindowButton button) {
144
this.quicklist = button.quicklist;
145
this.window = button.window;
146
this.create_quicklist_action_items();
147
this.create_end_items();
151
private void create_quicklist_action_items() {
152
foreach (QuickLists.Action action in quicklist.get_actions()) {
153
var name = action.name;
154
var menuitem = new Gtk.MenuItem.with_label(name);
155
menuitem.activate.connect(this.on_quicklist_action_menuitem_activate);
160
private void create_end_items() {
161
var menuitem_separator = new Gtk.SeparatorMenuItem();
162
var menuitem_close = new Gtk.MenuItem.with_label(_("Close"));
164
menuitem_close.activate.connect(this.on_menuitem_close_activate);
166
this.add(menuitem_separator);
167
this.add(menuitem_close);
170
private void on_quicklist_action_menuitem_activate(Gtk.MenuItem menuitem) {
171
var action = this.quicklist.get_action_from_name(menuitem.get_label());
172
Process.spawn_async(null, action.exec.split(" "), null, SpawnFlags.SEARCH_PATH, null, null);
175
private void on_menuitem_close_activate() {
176
this.window.close(Gtk.get_current_event_time());