2 #include <libxfce4panel/xfce-panel-plugin.h>
7 // dir & 1 = LEFT or RIGHT
8 // dir & 2 = TOP or BOTTOM
16 const int CORNER_DIR_COUNT
= 4;
19 XfcePanelPlugin
* plugin
;
28 static void cornerimg_construct (XfcePanelPlugin
*plugin
);
29 XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL (cornerimg_construct
);
31 static void gdk_color_to_doubles (GdkColor color
, double* output
)
33 const int R
=0, G
=1, B
=2;
34 output
[R
] = color
.red
/ 65535.0;
35 output
[G
] = color
.green
/ 65535.0;
36 output
[B
] = color
.blue
/ 65535.0;
39 static void drawing_update(CornerImg
* cimg
, cairo_t
* cr
)
41 double width
= cimg
->drawing
->allocation
.width
;
42 double height
= cimg
->drawing
->allocation
.height
;
44 gdk_color_to_doubles(cimg
->drawing
->style
->bg
[GTK_STATE_NORMAL
], pc
);
45 cairo_matrix_t matrix
= {width
, 0.0, 0.0, height
, 0.0, 0.0};
46 if (cimg
->corner_dir
& 1) // left or right?
51 if (cimg
->corner_dir
& 2)
57 cairo_set_matrix(cr
, &matrix
);
58 cairo_set_antialias(cr
, CAIRO_ANTIALIAS_GRAY
);
60 cairo_set_source_rgb(cr
, pc
[0], pc
[1], pc
[2]);
61 cairo_rectangle(cr
, 0.0, 0.0, 1.0, 1.0);
64 cairo_move_to(cr
, 1.0, 0.0);
65 cairo_line_to(cr
, 0.0, 0.0);
66 cairo_line_to(cr
, 0.0, 0.5);
67 cairo_curve_to(cr
, 0.0, 0.3, 0.2, 0.0, 1.0, 0.0);
70 cairo_set_source_rgb(cr
, 0.0, 0.0, 0.0);
74 static gboolean
drawing_on_expose(GtkWidget
* widget
,
75 GdkEventExpose
* event
,
78 CornerImg
* cimg
= (CornerImg
*) my_data
;
79 cairo_t
* cr
= gdk_cairo_create(widget
->window
);
81 event
->area
.x
, event
->area
.y
,
82 event
->area
.width
, event
->area
.height
);
84 drawing_update(cimg
, cr
);
89 void cornerimg_load_from_rc(CornerImg
* cimg
)
92 if (!(file
= xfce_panel_plugin_lookup_rc_file(cimg
->plugin
))) return;
93 XfceRc
* rc
= xfce_rc_simple_open(file
, TRUE
);
97 cimg
->corner_dir
= xfce_rc_read_int_entry(rc
, "CornerDir", 0);
102 void cornerimg_write_rc(CornerImg
* cimg
)
105 if (!(file
= xfce_panel_plugin_save_location(cimg
->plugin
, TRUE
))) return;
107 XfceRc
* rc
= xfce_rc_simple_open(file
, FALSE
);
111 xfce_rc_write_int_entry(rc
, "CornerDir", cimg
->corner_dir
);
116 static void cornerimg_set_size(XfcePanelPlugin
*plugin
,
120 gtk_widget_set_size_request(GTK_WIDGET(plugin
), size
/2, size
);
123 static void cornerimg_free_data(XfcePanelPlugin
*plugin
,
126 panel_slice_free(CornerImg
, cimg
);
129 static gboolean
cornerimg_toggle_dir(GtkWidget
* widget
, GdkEventButton
* event
,
132 if (event
->button
== 1)
135 if (cimg
->corner_dir
>= CORNER_DIR_COUNT
)
136 cimg
->corner_dir
= 0;
137 cairo_t
* cr
= gdk_cairo_create (cimg
->drawing
->window
);
138 drawing_update(cimg
, cr
);
140 cornerimg_write_rc(cimg
);
145 static void cornerimg_construct(XfcePanelPlugin
* plugin
)
147 CornerImg
*cimg
= panel_slice_new0 (CornerImg
);
148 cimg
->plugin
= plugin
;
149 cornerimg_load_from_rc(cimg
);
151 gtk_container_set_border_width(GTK_CONTAINER(plugin
), 0);
153 cimg
->eventbox
= gtk_event_box_new();
154 gtk_container_add(GTK_CONTAINER(plugin
), cimg
->eventbox
);
155 g_signal_connect(cimg
->eventbox
, "button-press-event",
156 G_CALLBACK(cornerimg_toggle_dir
), cimg
);
158 cimg
->drawing
= gtk_drawing_area_new();
159 g_signal_connect (cimg
->drawing
, "expose-event",
160 G_CALLBACK (drawing_on_expose
), cimg
);
161 gtk_container_add(GTK_CONTAINER(cimg
->eventbox
), cimg
->drawing
);
163 g_signal_connect(plugin
, "size-changed",
164 G_CALLBACK(cornerimg_set_size
), NULL
);
165 g_signal_connect(plugin
, "free-data",
166 G_CALLBACK (cornerimg_free_data
), cimg
);
168 gtk_widget_show_all(cimg
->eventbox
);
170 xfce_panel_plugin_add_action_widget (plugin
, GTK_WIDGET(cimg
->eventbox
));
171 cornerimg_set_size(plugin
, xfce_panel_plugin_get_size(plugin
), cimg
);