File: main.c

package info (click to toggle)
fbpanel 7.0-3
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 5,000 kB
  • ctags: 2,013
  • sloc: ansic: 11,684; sh: 404; python: 382; makefile: 315
file content (181 lines) | stat: -rw-r--r-- 4,585 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#include <gdk-pixbuf/gdk-pixbuf.h>

#include "panel.h"
#include "misc.h"
#include "plugin.h"
#include "bg.h"
#include "gtkbgbox.h"
#include "gtkbar.h"

#include "eggtraymanager.h"
#include "fixedtip.h"


//#define DEBUGPRN
#include "dbg.h"


typedef struct {
    plugin_instance plugin;
    GtkWidget *box;
    EggTrayManager *tray_manager;
    FbBg *bg;
    gulong sid;
} tray_priv;

static void
tray_bg_changed(FbBg *bg, GtkWidget *widget)
{
    ENTER;
    gtk_widget_set_size_request(widget, widget->allocation.width,
        widget->allocation.height);
    gtk_widget_hide(widget);
    if (gtk_events_pending())
        gtk_main_iteration();
    gtk_widget_show(widget);
    gtk_widget_set_size_request(widget, -1, -1);
    RET();
}

static void
tray_added (EggTrayManager *manager, GtkWidget *icon, tray_priv *tr)
{
    ENTER;
    gtk_box_pack_end(GTK_BOX(tr->box), icon, FALSE, FALSE, 0);
    gtk_widget_show(icon);
    gdk_display_sync(gtk_widget_get_display(icon));
    tray_bg_changed(NULL, tr->plugin.pwid);
    RET();
}

static void
tray_removed (EggTrayManager *manager, GtkWidget *icon, tray_priv *tr)
{
    ENTER;
    DBG("del icon\n");
    tray_bg_changed(NULL, tr->plugin.pwid);
    RET();
}

static void
message_sent (EggTrayManager *manager, GtkWidget *icon, const char *text,
    glong id, glong timeout, void *data)
{
    /* FIXME multihead */
    int x, y;
    
    ENTER;
    gdk_window_get_origin (icon->window, &x, &y);
    fixed_tip_show (0, x, y, FALSE, gdk_screen_height () - 50, text);
    RET();
}

static void
message_cancelled (EggTrayManager *manager, GtkWidget *icon, glong id,
    void *data)
{
    ENTER;
    RET();
}

static void
tray_destructor(plugin_instance *p)
{
    tray_priv *tr = (tray_priv *) p;

    ENTER;
    g_signal_handler_disconnect(tr->bg, tr->sid);
    g_object_unref(tr->bg);
    /* Make sure we drop the manager selection */
    if (tr->tray_manager)
        g_object_unref(G_OBJECT(tr->tray_manager));
    fixed_tip_hide();
    RET();
}


static void
tray_size_alloc(GtkWidget *widget, GtkAllocation *a,
    tray_priv *tr)
{
    int dim, size;

    ENTER;
    size = tr->plugin.panel->max_elem_height;
    if (tr->plugin.panel->orientation == GTK_ORIENTATION_HORIZONTAL) 
        dim = a->height / size;
    else
        dim = a->width / size;
    DBG("width=%d height=%d iconsize=%d -> dim=%d\n",
        a->width, a->height, size, dim);
    gtk_bar_set_dimension(GTK_BAR(tr->box), dim);
    RET();
}
  

static int
tray_constructor(plugin_instance *p)
{
    tray_priv *tr;
    GdkScreen *screen;
    GtkWidget *ali;
    
    ENTER;
    tr = (tray_priv *) p;
    class_get("tray");
    ali = gtk_alignment_new(0.5, 0.5, 0, 0);
    g_signal_connect(G_OBJECT(ali), "size-allocate",
        (GCallback) tray_size_alloc, tr);
    gtk_container_set_border_width(GTK_CONTAINER(ali), 0);
    gtk_container_add(GTK_CONTAINER(p->pwid), ali);
    tr->box = gtk_bar_new(p->panel->orientation, 0,
        p->panel->max_elem_height, p->panel->max_elem_height);
    gtk_container_add(GTK_CONTAINER(ali), tr->box);
    gtk_container_set_border_width(GTK_CONTAINER (tr->box), 0);
    gtk_widget_show_all(ali);
    tr->bg = fb_bg_get_for_display();
    tr->sid = g_signal_connect(tr->bg, "changed",
        G_CALLBACK(tray_bg_changed), p->pwid);
    
    screen = gtk_widget_get_screen(p->panel->topgwin);
    
    if (egg_tray_manager_check_running(screen)) {
        tr->tray_manager = NULL;
        ERR("tray: another systray already running\n");
        RET(1);
    }
    tr->tray_manager = egg_tray_manager_new ();
    if (!egg_tray_manager_manage_screen (tr->tray_manager, screen))
        g_printerr("tray: can't get the system tray manager selection\n");
    
    g_signal_connect(tr->tray_manager, "tray_icon_added",
        G_CALLBACK(tray_added), tr);
    g_signal_connect(tr->tray_manager, "tray_icon_removed",
        G_CALLBACK(tray_removed), tr);
    g_signal_connect(tr->tray_manager, "message_sent",
        G_CALLBACK(message_sent), tr);
    g_signal_connect(tr->tray_manager, "message_cancelled",
        G_CALLBACK(message_cancelled), tr);
    
    gtk_widget_show_all(tr->box);
    RET(1);

}


static plugin_class class = {
    .count       = 0,
    .type        = "tray",
    .name        = "System tray",
    .version     = "1.0",
    .description = "System tray aka Notification Area",
    .priv_size   = sizeof(tray_priv),

    .constructor = tray_constructor,
    .destructor = tray_destructor,
};
static plugin_class *class_ptr = (plugin_class *) &class;