~leftyfb/gstm/gstm

« back to all changes in this revision

Viewing changes to src/notarea.c

  • Committer: Mattias Eriksson
  • Date: 2009-10-29 17:45:24 UTC
  • Revision ID: mattias.eriksson@ardendo.se-20091029174524-8h0fmfa68i607us9
Initial checkin of gstm 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *            notarea.c
 
3
 *
 
4
 *  Thu Aug  4 14:57:32 2005
 
5
 *  Copyright  2005  Mark Smulders
 
6
 *  msmulders@elsar.nl
 
7
 ****************************************************************************/
 
8
 /*
 
9
 * System tray icon for gSTM
 
10
 *
 
11
 * Inspired by the Gaim plugin:
 
12
 * Robert McQueen <robot101@debian.org>
 
13
 * Herman Bloggs <hermanator12002@yahoo.com>
 
14
 * Inspired by a similar plugin by:
 
15
 *  John (J5) Palmieri <johnp@martianrock.com>
 
16
 * 
 
17
 * This program is free software; you can redistribute it and/or
 
18
 * modify it under the terms of the GNU General Public License as
 
19
 * published by the Free Software Foundation; either version 2 of the
 
20
 * License, or (at your option) any later version.
 
21
 *
 
22
 * This program is distributed in the hope that it will be useful, but
 
23
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
25
 * General Public License for more details.
 
26
 * 
 
27
 * You should have received a copy of the GNU General Public License
 
28
 * along with this program; if not, write to the Free Software
 
29
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
30
 * 02111-1307, USA.
 
31
 */
 
32
 
 
33
#include <gtk/gtk.h>
 
34
#include "eggtrayicon.h"
 
35
EggTrayIcon *docklet = NULL;
 
36
static GtkWidget *image = NULL;
 
37
extern void docklet_clicked(int);
 
38
 
 
39
static void docklet_x11_destroyed_cb(GtkWidget *widget, void *data);
 
40
 
 
41
static void
 
42
docklet_x11_clicked_cb(GtkWidget *button, GdkEventButton *event, void *data)
 
43
{
 
44
        if (event->type != GDK_BUTTON_PRESS)
 
45
                return;
 
46
 
 
47
        docklet_clicked(event->button);
 
48
}
 
49
 
 
50
void
 
51
docklet_x11_destroy()
 
52
{
 
53
        g_signal_handlers_disconnect_by_func(G_OBJECT(docklet),
 
54
                G_CALLBACK(docklet_x11_destroyed_cb), NULL);
 
55
        gtk_widget_destroy(GTK_WIDGET(docklet));
 
56
 
 
57
        g_object_unref(G_OBJECT(docklet));
 
58
        docklet = NULL;
 
59
}
 
60
 
 
61
void
 
62
docklet_x11_create()
 
63
{
 
64
        GtkWidget *box;
 
65
        GdkPixbuf *pb, *pbsmall;
 
66
 
 
67
        if (docklet) {
 
68
                /* if this is being called when a tray icon exists, it's because
 
69
                   something messed up. try destroying it before we proceed,
 
70
                   although docklet_refcount may be all hosed. hopefully won't happen. */
 
71
                docklet_x11_destroy();
 
72
        }
 
73
 
 
74
        docklet = egg_tray_icon_new("gSTM");
 
75
        box = GTK_WIDGET(gtk_event_box_new());
 
76
        image = GTK_WIDGET(gtk_image_new());
 
77
 
 
78
        g_signal_connect(G_OBJECT(docklet), "destroy", G_CALLBACK(docklet_x11_destroyed_cb), NULL);
 
79
        g_signal_connect(G_OBJECT(box), "button-press-event", G_CALLBACK(docklet_x11_clicked_cb), NULL);
 
80
 
 
81
        gtk_container_add(GTK_CONTAINER(box), image);
 
82
        gtk_container_add(GTK_CONTAINER(docklet), box);
 
83
 
 
84
        if(!gtk_check_version(2,4,0))
 
85
                g_object_set(G_OBJECT(box), "visible-window", FALSE, NULL);
 
86
 
 
87
        gtk_widget_show_all(GTK_WIDGET(docklet));
 
88
 
 
89
        /* ref the docklet before we bandy it about the place */
 
90
        g_object_ref(G_OBJECT(docklet));
 
91
 
 
92
        /* set gSTM icon */
 
93
        pb = GDK_PIXBUF(create_pixbuf("gstm/gSTM.xpm"));
 
94
        /* resize the icon to a more appropriate size */
 
95
        pbsmall = gdk_pixbuf_scale_simple(pb,24,24,GDK_INTERP_BILINEAR); //FIXME? static size
 
96
        
 
97
        gtk_image_set_from_pixbuf(GTK_IMAGE(image),pbsmall);
 
98
}
 
99
 
 
100
static gboolean
 
101
docklet_x11_create_cb()
 
102
{
 
103
        docklet_x11_create();
 
104
        
 
105
        return FALSE; /* for when we're called by the glib idle handler */
 
106
}
 
107
 
 
108
static void
 
109
docklet_x11_destroyed_cb(GtkWidget *widget, void *data)
 
110
{
 
111
 
 
112
        g_object_unref(G_OBJECT(docklet));
 
113
        docklet = NULL;
 
114
 
 
115
        g_idle_add(docklet_x11_create_cb, NULL);
 
116
}
 
117
 
 
118
void
 
119
docklet_x11_position_menu(GtkMenu *menu, int *x, int *y, gboolean *push_in,
 
120
                                                  gpointer user_data)
 
121
{
 
122
        GtkWidget *widget = GTK_WIDGET(docklet);
 
123
        GtkRequisition req;
 
124
        gint menu_xpos, menu_ypos;
 
125
 
 
126
        gtk_widget_size_request(GTK_WIDGET(menu), &req);
 
127
        gdk_window_get_origin(widget->window, &menu_xpos, &menu_ypos);
 
128
 
 
129
        menu_xpos += widget->allocation.x;
 
130
        menu_ypos += widget->allocation.y;
 
131
 
 
132
        if (menu_ypos > gdk_screen_get_height(gtk_widget_get_screen(widget)) / 2)
 
133
                menu_ypos -= req.height;
 
134
        else
 
135
                menu_ypos += widget->allocation.height;
 
136
 
 
137
        *x = menu_xpos;
 
138
        *y = menu_ypos;
 
139
 
 
140
        *push_in = TRUE;
 
141
}