~marcobiscaro2112/unity/fixes-724739

« back to all changes in this revision

Viewing changes to src/PanelTray.cpp

  • Committer: Neil Jagdish Patel
  • Date: 2011-02-14 19:56:50 UTC
  • mto: This revision was merged to the branch mainline in revision 867.
  • Revision ID: neil.patel@canonical.com-20110214195650-xq5qd4287c6qk176
Size and position systray window

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include "PanelTray.h"
20
20
 
21
21
PanelTray::PanelTray ()
 
22
: _n_children (0),
 
23
  _last_x (0),
 
24
  _last_y (0)
22
25
{
23
 
  _window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 
26
  _window = gtk_window_new (GTK_WINDOW_POPUP);
24
27
  gtk_window_set_type_hint (GTK_WINDOW (_window), GDK_WINDOW_TYPE_HINT_DOCK);
25
28
  gtk_window_set_keep_above (GTK_WINDOW (_window), TRUE);
26
29
  gtk_window_set_skip_pager_hint (GTK_WINDOW (_window), TRUE);
27
30
  gtk_window_set_skip_taskbar_hint (GTK_WINDOW (_window), TRUE);
28
 
  gtk_window_resize (GTK_WINDOW (_window), 24, 24);
 
31
  gtk_window_resize (GTK_WINDOW (_window), 1, 24);
29
32
  gtk_window_move (GTK_WINDOW (_window), 200, 12);
30
33
  gtk_widget_set_name (_window, "UnityPanelApplet");
31
34
  gtk_widget_set_colormap (_window, gdk_screen_get_rgba_colormap (gdk_screen_get_default ())); 
32
35
  gtk_widget_realize (_window);
33
36
  gdk_window_set_back_pixmap (_window->window, NULL, FALSE);
34
37
  gtk_widget_set_app_paintable (_window, TRUE);
35
 
 
36
 
  _tray = na_tray_new_for_screen (gdk_screen_get_default (),
37
 
                                  GTK_ORIENTATION_HORIZONTAL,
38
 
                                  (NaTrayFilterCallback)FilterTrayCallback,
39
 
                                  this);
40
 
 
41
 
  gtk_container_add (GTK_CONTAINER (_window), GTK_WIDGET (_tray));
42
 
  gtk_widget_show (GTK_WIDGET (_tray));
43
 
 
44
 
  gtk_widget_show_all (_window);
 
38
  g_signal_connect (_window, "expose-event", G_CALLBACK (PanelTray::OnTrayExpose), this);
 
39
 
 
40
  if (!g_getenv ("UNITY_PANEL_TRAY_DISABLE"))
 
41
  {
 
42
    _tray = na_tray_new_for_screen (gdk_screen_get_default (),
 
43
                                    GTK_ORIENTATION_HORIZONTAL,
 
44
                                    (NaTrayFilterCallback)FilterTrayCallback,
 
45
                                    this);
 
46
    g_signal_connect (na_tray_get_manager (_tray), "tray_icon_removed",
 
47
                      G_CALLBACK (PanelTray::OnTrayIconRemoved), this);
 
48
 
 
49
    gtk_container_add (GTK_CONTAINER (_window), GTK_WIDGET (_tray));
 
50
    gtk_widget_show (GTK_WIDGET (_tray));
 
51
 
 
52
    gtk_widget_show_all (_window);
 
53
  }
45
54
}
46
55
 
47
56
PanelTray::~PanelTray ()
48
57
{
49
 
 
50
58
}
51
59
 
52
 
gboolean
53
 
PanelTray::FilterTrayCallback (NaTray *tray, NaTrayChild *child, PanelTray *self)
 
60
void
 
61
PanelTray::Draw (nux::GraphicsEngine& gfx_content, bool force_draw)
54
62
{
55
 
  return TRUE;
 
63
  nux::Geometry geo = GetGeometry ();
 
64
 
 
65
  if (geo.x != _last_x || geo.y != _last_y)
 
66
  {
 
67
    _last_x = geo.x;
 
68
    _last_y = geo.y;
 
69
 
 
70
    gtk_window_move (GTK_WINDOW (_window), geo.x, geo.y + 24);
 
71
  }
56
72
}
57
73
 
58
74
Window
61
77
  return GDK_WINDOW_XWINDOW (_window->window);
62
78
}
63
79
 
 
80
void
 
81
PanelTray::Sync ()
 
82
{
 
83
  SetMinMaxSize (_n_children * 24, 24);
 
84
  ComputeChildLayout ();
 
85
 
 
86
  QueueDraw ();
 
87
}
 
88
 
 
89
gboolean
 
90
PanelTray::FilterTrayCallback (NaTray *tray, NaTrayChild *icon, PanelTray *self)
 
91
{
 
92
  char *res_name = NULL;
 
93
  char *res_class = NULL;
 
94
 
 
95
  na_tray_child_get_wm_class (icon, &res_name, &res_class);
 
96
  if (na_tray_child_has_alpha (icon))
 
97
    na_tray_child_set_composited (icon, TRUE);
 
98
 
 
99
  g_debug ("TrayChild %s: %s %s", na_tray_child_get_title (icon), res_name, res_class);
 
100
  
 
101
  g_free (res_name);
 
102
  g_free (res_class);
 
103
 
 
104
  self->_n_children++;  
 
105
 
 
106
  g_idle_add ((GSourceFunc)IdleSync, self);
 
107
  return TRUE;
 
108
}
 
109
 
 
110
void
 
111
PanelTray::OnTrayIconRemoved (NaTrayManager *manager, NaTrayChild *child, PanelTray *self)
 
112
{
 
113
  g_idle_add ((GSourceFunc)IdleSync, self);
 
114
  self->_n_children--;
 
115
}
 
116
 
 
117
gboolean
 
118
PanelTray::IdleSync (PanelTray *self)
 
119
{
 
120
  self->Sync ();
 
121
  return FALSE;
 
122
}
 
123
 
 
124
gboolean
 
125
PanelTray::OnTrayExpose (GtkWidget *widget, GdkEventExpose *ev, PanelTray *tray)
 
126
{
 
127
  cairo_t *cr = gdk_cairo_create (widget->window);
 
128
  GtkAllocation alloc;
 
129
 
 
130
  gtk_widget_get_allocation (widget, &alloc);
 
131
 
 
132
  gdk_cairo_region (cr, ev->region);
 
133
  cairo_clip (cr);
 
134
 
 
135
  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
 
136
  cairo_paint (cr);
 
137
 
 
138
  cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
 
139
  cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.0f);
 
140
  cairo_rectangle (cr, 0, 0, alloc.width, alloc.height);
 
141
  cairo_fill (cr);
 
142
 
 
143
  cairo_destroy (cr);
 
144
 
 
145
  gtk_container_propagate_expose (GTK_CONTAINER (widget),
 
146
                                  gtk_bin_get_child (GTK_BIN (widget)),
 
147
                                  ev);
 
148
 
 
149
  return FALSE;
 
150
}
 
151
 
64
152
//
65
153
// We don't use these
66
154
//