More skip hints
[gregoa/zavai.git] / src / app_wm.vala
1 /*
2  * app_wm - zavai window management functions
3  *
4  * Copyright (C) 2009  Enrico Zini <enrico@enricozini.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 using GLib;
22
23 namespace zavai {
24 namespace ui {
25 namespace wm {
26
27 /*
28 static void print_window_state(Gtk.Window w)
29 {
30         Gdk.WindowState state = w.window.get_state();
31         int istate = (int) state;
32         bool is_icon = (state & Gdk.WindowState.ICONIFIED) != 0;
33         bool is_visible = w.visible;
34         bool is_focus = w.is_focus;
35         bool has_focus = ((Gtk.Widget)w).has_focus;
36         bool is_active = w.is_active;
37         bool is_toplevel = w.is_toplevel();
38         bool is_tfocus = w.has_toplevel_focus;
39
40         stderr.printf("istate: %d; is_icon: %s; is_visible: %s; is_focus: %s; has_focus: %s, is_active: %s; is_toplevel: %s; is_tfocus: %s\n",
41                         istate,
42                         is_icon ? "true" : "false",
43                         is_visible ? "true" : "false",
44                         is_focus ? "true" : "false",
45                         has_focus ? "true" : "false",
46                         is_active ? "true" : "false",
47                         is_toplevel ? "true" : "false",
48                         is_tfocus ? "true" : "false"
49                      );
50 }
51 */
52
53 public class RaiseIcon : Gtk.StatusIcon
54 {
55         public RaiseIcon()
56         {
57                 activate += on_activate;
58                 zavai.app.visibility_changed += on_visibility_changed;
59                 update_icon();
60         }
61
62         private void on_visibility_changed(bool visible)
63         {
64                 update_icon();
65         }
66
67         private void on_activate()
68         {
69                 zavai.app.toggle_visibility();
70                 update_icon();
71         }
72
73         protected void update_icon()
74         {
75                 string name = zavai.config.icondir + "/";
76                 if (!zavai.app.visibility)
77                         name += "zavai_on.png";
78                 else
79                         name += "zavai_off.png";
80                 set_from_file(name);
81         }
82 }
83
84 public class CloseOrBack : Gtk.StatusIcon
85 {
86         public CloseOrBack()
87         {
88                 activate += on_activate;
89                 zavai.app.visibility_changed += on_visibility_changed;
90                 update_icon();
91         }
92
93         private void on_visibility_changed(bool visible)
94         {
95                 update_icon();
96         }
97
98         private void on_activate()
99         {
100                 if (zavai.app.visibility)
101                 {
102                         // Back
103                 } else {
104                         // Close current app
105                         Gdk.Window w = zavai.app.get_screen().get_active_window();
106                         if (w != zavai.app.window)
107                         {
108                                 w.destroy();
109                         }
110                 }
111         }
112
113         protected void update_icon()
114         {
115                 string name = zavai.config.icondir + "/";
116                 if (!zavai.app.visibility)
117                         name += "quit_on.png";
118                 else
119                         name += "quit_off.png";
120                 set_from_file(name);
121         }
122 }
123
124 public class WindowList : Applet
125 {
126         Wnck.Tasklist selector;
127
128         public WindowList(string label)
129         {
130                 _label = label;
131                 selector = new Wnck.Tasklist(Wnck.Screen.get_default());
132                 pack_start(selector, true, true, 0);
133         }
134 }
135
136
137 RaiseIcon raise_icon;
138 CloseOrBack close_or_back;
139 WindowList window_list;
140
141 public void init()
142 {
143         raise_icon = new RaiseIcon();
144         raise_icon.set_visible(true);
145
146         close_or_back = new CloseOrBack();
147         close_or_back.set_visible(true);
148
149         window_list = new WindowList("Current apps");
150         zavai.registry.register_applet("wm.list", window_list);
151         zavai.registry.getmenu("menu.main").add_applet("wm.list");
152 }
153
154 }
155 }
156 }