~awn-curves-team/awn/awn-curves

« back to all changes in this revision

Viewing changes to libawn/awn-applet-simple.c

  • Committer: Torsten
  • Date: 2007-10-31 04:35:09 UTC
  • Revision ID: torsten.haedrich@gmail.com-20071031043509-fvr0jhy0wlr7yp9r
merge with 0.2-stable-testing

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
        gint bar_height;
52
52
        gint bar_angle;
53
53
 
54
 
        gboolean temp;
55
54
};
56
55
 
57
56
static void 
59
58
{
60
59
        AwnAppletSimplePrivate *priv;
61
60
        GdkPixbuf *old0, *old1;
 
61
        int refcount = 0;
62
62
     
63
63
        priv = simple->priv;
64
64
 
69
69
        {
70
70
                priv->icon_height = gdk_pixbuf_get_height (priv->org_icon);
71
71
                priv->icon_width = gdk_pixbuf_get_width (priv->org_icon);
72
 
                priv->icon = priv->org_icon;
 
72
                priv->icon = gdk_pixbuf_copy (priv->org_icon);
73
73
        }
74
74
        else
75
75
        {
81
81
                                                     GDK_INTERP_BILINEAR);
82
82
        }
83
83
 
 
84
        g_object_ref (priv->icon);
84
85
        priv->reflect = gdk_pixbuf_flip (priv->icon, FALSE);
85
 
        g_object_ref (priv->icon);
86
86
        g_object_ref (priv->reflect);
87
87
        
88
 
        /* We need to unref twice because python hurts kittens */
89
 
        if (G_IS_OBJECT (old0))
90
 
        {
91
 
                 g_object_unref (old0);
92
 
                 if (G_IS_OBJECT (old0) && priv->temp)
93
 
                        g_object_unref (old0);
94
 
        }
95
 
        if (G_IS_OBJECT (old1))
96
 
        {
97
 
                 g_object_unref (old1);
98
 
                 if (G_IS_OBJECT (old1) && priv->temp)
99
 
                        g_object_unref (old1);
100
 
        }
 
88
        if (old0) {
 
89
                for (refcount = (G_OBJECT (old0))->ref_count; refcount > 0; refcount--) {
 
90
                        g_object_unref (old0);
 
91
                }
 
92
        }
 
93
        if (old1) {
 
94
                for (refcount = (G_OBJECT (old1))->ref_count; refcount > 0; refcount--) {
 
95
                        g_object_unref (old1);
 
96
                }
 
97
        }
 
98
        /* for some reason priv->reflect is not always a valid pixbuf.
 
99
           my suspicion is that we are seeing a gdk bug here.  So...if
 
100
           priv->reflect isn't a good pixbuf, well... let's try making
 
101
           one from priv->org_icon */
 
102
        if (!GDK_IS_PIXBUF (priv->reflect)) {
 
103
                priv->reflect = gdk_pixbuf_flip (priv->org_icon, FALSE);
 
104
        }
 
105
 
101
106
        // awn-effects require the window to be 25% bigger than icon
102
107
        gtk_widget_set_size_request (GTK_WIDGET (simple), 
103
108
                                     priv->icon_width *5/4,
108
113
void
109
114
awn_applet_simple_set_icon (AwnAppletSimple *simple, GdkPixbuf *pixbuf)
110
115
{
111
 
        AwnAppletSimplePrivate *priv;
112
 
        GdkPixbuf *old0;
113
 
 
114
 
        g_return_if_fail (AWN_IS_APPLET_SIMPLE (simple));
115
 
        g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
 
116
        g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
116
117
        
117
 
        priv = simple->priv;
118
 
 
119
 
        if (pixbuf == priv->org_icon) {
120
 
                priv->bar_height_on_icon_recieved = priv->bar_height;
121
 
                adjust_icon(simple);
122
 
                return;
123
 
        }
124
 
 
125
 
        old0 = priv->org_icon;
126
 
        priv->org_icon = pixbuf;
127
 
        priv->bar_height_on_icon_recieved = priv->bar_height;
128
 
 
129
 
        /* We need to unref twice because python hurts kittens */
130
 
        if (G_IS_OBJECT (old0))
131
 
        {
132
 
                 g_object_unref (old0);
133
 
                 if (G_IS_OBJECT (old0) && priv->temp)
134
 
                        g_object_unref (old0);
135
 
        }     
136
 
 
137
 
        adjust_icon(simple);
138
 
        priv->temp = FALSE;
 
118
        /* awn_applet_simple_set_icon is not heavily used.
 
119
           Previous inplementation was causing nasty leaks.
 
120
           This fix seems sensible, easy to maintain.
 
121
           And it works.  Note we are making a copy here so
 
122
           the unref in set_temp_icon leaves the user's original
 
123
           untouched.
 
124
         */
 
125
        awn_applet_simple_set_temp_icon (simple, gdk_pixbuf_copy (pixbuf));
139
126
}
140
127
 
141
128
void 
143
130
{
144
131
        AwnAppletSimplePrivate *priv;
145
132
        GdkPixbuf *old0;
 
133
        int refcount;
146
134
 
147
135
        g_return_if_fail (AWN_IS_APPLET_SIMPLE (simple));
148
136
        g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
149
137
        
150
138
        priv = simple->priv;
151
139
 
152
 
        if (pixbuf == priv->org_icon) {
153
 
                priv->bar_height_on_icon_recieved = priv->bar_height;
154
 
                adjust_icon(simple);
155
 
                return;
156
 
        }
 
140
        /* let's make sure that an applet can't screw around with OUR
 
141
           pixbuf.  We'll make our own copy, and free up theirs.
 
142
         */
 
143
        old0 = pixbuf;
 
144
        pixbuf = gdk_pixbuf_copy (pixbuf);
 
145
        g_object_unref (old0);
157
146
 
158
147
        old0 = priv->org_icon;
159
148
        priv->org_icon = pixbuf;
160
149
        priv->bar_height_on_icon_recieved = priv->bar_height;
161
150
 
162
 
        /* We need to unref twice because python hurts kittens */
163
 
        if (G_IS_OBJECT (old0))
164
 
        {
165
 
                 g_object_unref (old0);
166
 
                 if (G_IS_OBJECT (old0) && priv->temp)
167
 
                        g_object_unref (old0);
168
 
        }     
 
151
        if (old0) {
 
152
                for (refcount = (G_OBJECT (old0))->ref_count; refcount > 0; refcount--) {
 
153
                        g_object_unref (old0);
 
154
                }
 
155
        }
169
156
 
170
157
        adjust_icon(simple);
171
 
        priv->temp = TRUE;
172
158
}
173
159
 
174
160
static gboolean 
180
166
 
181
167
        priv = AWN_APPLET_SIMPLE (widget)->priv;
182
168
 
 
169
        /* For some reason, priv->reflect is not always a valid pixbuf.
 
170
           my suspicion is that we are seeing a gdk bug here. So... if
 
171
           priv->reflect isn't a good pixbuf well.. let's try making one from
 
172
           priv->org_icon.  I'm not happy as I'm not exactly sure of the root
 
173
           cause of this...  but this does resolve the issue */
 
174
        if (!GDK_IS_PIXBUF (priv->reflect)) {
 
175
                priv->reflect = gdk_pixbuf_flip (priv->icon, FALSE);
 
176
        }
 
177
        if (!GDK_IS_PIXBUF (priv->reflect)) {
 
178
                priv->reflect = gdk_pixbuf_flip (priv->org_icon, FALSE);
 
179
        }
 
180
 
183
181
        width = widget->allocation.width;
184
182
        height = widget->allocation.height;
185
183
 
269
267
        priv = simple->priv = AWN_APPLET_SIMPLE_GET_PRIVATE (simple);
270
268
 
271
269
        priv->icon = NULL;
 
270
        priv->org_icon = NULL;
272
271
        priv->reflect = NULL;
273
272
        priv->icon_height = 0;
274
273
        priv->icon_width = 0;