/[dino]/glashctl/wmdockicon.cpp
ViewVC logotype

Contents of /glashctl/wmdockicon.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download)
Thu Jul 19 21:50:05 2007 UTC (17 years, 3 months ago) by larsl
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +1 -1 lines
Upgraded to GPL version 3 or later

1 // -*- Mode: C++ ; c-basic-offset: 2 -*-
2 /****************************************************************************
3 GLASHCtl - a simple tray applet for controlling lashd
4
5 Copyright (C) 2006 Nedko Arnaudov <nedko@arnaudov.name>
6 Modified by Lars Luthman (blame all bugs on me!)
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; version 3 of the License.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 ****************************************************************************/
21
22 #include <iostream>
23
24 #include <gtk/gtkmain.h>
25
26 #include "wmdockicon.hpp"
27
28 #include <gdk/gdkx.h>
29
30 #include "lash_active.xpm"
31 #include "lash_inactive.xpm"
32
33
34 using namespace Gdk;
35 using namespace Glib;
36 using namespace sigc;
37 using namespace std;
38
39
40 WMDockIcon::WMDockIcon() {
41
42 // Set initial Gdk::Window attributes
43 GdkWindowAttr attr;
44 GdkWindowAttr attri;
45 memset(&attr, 0, sizeof(GdkWindowAttr));
46 attr.width = 64;
47 attr.height = 64;
48 attr.title = "wmglashctl";
49 attr.event_mask = GDK_BUTTON_PRESS_MASK;
50 attr.wclass = GDK_INPUT_OUTPUT;
51 attr.visual = gdk_visual_get_system();
52 attr.colormap = gdk_colormap_get_system();
53 attr.wmclass_name = "wmglashctl";
54 attr.wmclass_class = "wmglashctl";
55 attr.window_type = GDK_WINDOW_TOPLEVEL;
56
57 // Make a copy for the iconwin - parameters are the same
58 memcpy(&attri, &attr, sizeof(GdkWindowAttr));
59 attri.window_type = GDK_WINDOW_CHILD;
60
61 // Create dummy main window
62 // XXX why can't I create a Gdk::Window without a parent window?
63 if (!(m_win = wrap((GdkWindowObject*)gdk_window_new(0, &attr,
64 GDK_WA_TITLE |
65 GDK_WA_VISUAL |
66 GDK_WA_WMCLASS |
67 GDK_WA_COLORMAP)))) {
68 cerr<<"FATAL: Cannot make toplevel window"<<endl;
69 exit(1);
70 }
71
72 // Create icon window
73 if (!(m_iconwin = Gdk::Window::create(m_win, &attri,GDK_WA_TITLE |
74 GDK_WA_WMCLASS))) {
75 cerr<<"FATAL: Cannot make icon window"<<endl;
76 exit(1);
77 }
78
79 // This X hackery is needed to make the dockapp work in Fluxbox
80 XSizeHints sizehints;
81 sizehints.flags = USSize;
82 sizehints.width = 64;
83 sizehints.height = 64;
84 ::Window win = GDK_WINDOW_XWINDOW(m_win->gobj());
85 XSetWMNormalHints(GDK_WINDOW_XDISPLAY(m_win->gobj()), win, &sizehints);
86
87 // Create background pixmaps and set the window shape
88 Glib::RefPtr<Gdk::Bitmap> mask;
89 m_active_pixmap = Gdk::Pixmap::create_from_xpm(Gdk::Colormap::get_system(),
90 mask, Color(),
91 lash_active_xpm);
92 m_inactive_pixmap = Gdk::Pixmap::create_from_xpm(Gdk::Colormap::get_system(),
93 mask, Color(),
94 lash_inactive_xpm);
95 m_win->shape_combine_mask(mask, 0, 0);
96 m_iconwin->shape_combine_mask(mask, 0, 0);
97 m_win->set_back_pixmap(m_inactive_pixmap, false);
98 m_iconwin->set_back_pixmap(m_inactive_pixmap, false);
99
100 // Set some window hints
101 m_win->set_decorations(WMDecoration(0));
102 m_win->set_skip_taskbar_hint(true);
103 m_win->set_icon(m_iconwin, RefPtr<Gdk::Pixmap>(0), RefPtr<Bitmap>(0));
104 m_win->set_group(m_win);
105 m_win->show();
106
107 // This X hackery is also needed to make the dockapp work in Fluxbox
108 XWMHints wmhints;
109 ::Window iconwin = GDK_WINDOW_XWINDOW(m_iconwin->gobj());
110 wmhints.initial_state = WithdrawnState;
111 wmhints.icon_window = iconwin;
112 wmhints.icon_x = 0;
113 wmhints.icon_y = 0;
114 wmhints.window_group = win;
115 wmhints.flags = (StateHint | IconWindowHint |
116 IconPositionHint | WindowGroupHint);
117 XSetWMHints(GDK_WINDOW_XDISPLAY(m_win->gobj()), win, &wmhints);
118
119 // We can't connect directly to a Gdk::Window, so we need to filter the
120 // events before they reach GTK
121 gdk_event_handler_set(&WMDockIcon::button_pressed, this, 0);
122 }
123
124
125 void WMDockIcon::lashd_started() {
126 m_iconwin->set_back_pixmap(m_active_pixmap, false);
127 m_iconwin->clear();
128 }
129
130
131 void WMDockIcon::lashd_stopped() {
132 m_iconwin->set_back_pixmap(m_inactive_pixmap, false);
133 m_iconwin->clear();
134 }
135
136
137 void WMDockIcon::button_pressed(GdkEvent* event, gpointer data) {
138 WMDockIcon* me = static_cast<WMDockIcon*>(data);
139 if (event->type == GDK_BUTTON_PRESS &&
140 event->button.button == 3 &&
141 event->button.window == me->m_iconwin->gobj()) {
142 me->signal_popup(event->button.button, event->button.time);
143 return;
144 }
145 gtk_main_do_event(event);
146 }

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26