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
| #include <gtk/gtk.h>
#include <gdk/gdkscreen.h>
#include <cairo.h>
/*
* This program shows you how to create semi-transparent windows,
* without any of the historical screenshot hacks. It requires
* a modern system, with a compositing manager. I use xcompmgr
* and the nvidia drivers with RenderAccel, and it works well.
*
* I'll take you through each step as we go. Minimal GTK+ knowledge is
* assumed.
*/
static void screen_changed(GtkWidget *widget, GdkScreen *old_screen, gpointer user_data);
static gboolean expose(GtkWidget *widget, GdkEventExpose *event, gpointer user_data);
static void hello(GtkWidget *widget, gpointer data);
static void callbac(GtkWidget *widget, gpointer data);
static void create_app(GtkWidget *vBox, gpointer data);
/* Only some X servers support alpha channels. Always have a fallback */
gboolean supports_alpha = FALSE;
int main(int argc, char **argv) {
/* boilerplate initialization code */
gtk_init(&argc, &argv);
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(G_OBJECT(window), "delete-event", gtk_main_quit, NULL);
GtkWidget *pHBox = gtk_hbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), pHBox);
GtkWidget *event_box = gtk_event_box_new ();
gtk_widget_set_events(event_box, GDK_BUTTON_PRESS_MASK);
g_signal_connect(event_box, "button_press_event", G_CALLBACK (callbac), NULL);
gtk_widget_realize (event_box);
/* Chargement d'une image a partir d'un fichier */
create_app(pHBox, "1111111111111111");
create_app(pHBox, "22222222");
create_app(pHBox, "3333333333333333444444444");
GtkWidget *button = gtk_button_new_with_label ("Hello World");
g_signal_connect (button, "clicked", G_CALLBACK (hello), NULL);
g_signal_connect(G_OBJECT(window), "expose-event", G_CALLBACK(expose), NULL);
g_signal_connect(G_OBJECT(window), "screen-changed", G_CALLBACK(screen_changed), NULL);
/* initialize for the current display */
screen_changed(window, NULL, NULL);
//supports_alpha=FALSE; test
gtk_widget_set_app_paintable(window, supports_alpha);
/* Run the program */
gtk_widget_show_all(window);
gtk_main();
return 0;
}
static void screen_changed(GtkWidget *widget, GdkScreen *old_screen, gpointer userdata) {
GdkScreen *screen = gtk_widget_get_screen(widget);
GdkColormap *colormap = gdk_screen_get_rgba_colormap(screen);
if (!colormap) {
printf("Your screen does not support alpha channels!\n");
colormap = gdk_screen_get_rgb_colormap(screen);
supports_alpha = FALSE;
}
else {
printf("Your screen supports alpha channels!\n");
supports_alpha = TRUE;
}
/* Now we have a colormap appropriate for the screen, use it */
gtk_widget_set_colormap(widget, colormap);
}
/* This is called when we need to draw the windows contents */
static gboolean expose(GtkWidget *widget, GdkEventExpose *event, gpointer userdata) {
cairo_t *cr = gdk_cairo_create(widget->window);
if (supports_alpha)
cairo_set_source_rgba (cr, 1.0, 1.0, 0.0, 0.30); /* transparent */
else
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* opaque white */
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); /* draw the background */
cairo_paint(cr);
cairo_destroy(cr);
return FALSE;
}
static void create_app( GtkWidget *hBox, gpointer data ) {
GtkWidget *pVBox = gtk_vbox_new(FALSE, 0);
GtkWidget *pImage = gtk_image_new_from_file("/usr/local/src/myGtkMenu/oxygen-icons/im-qq.png");
gtk_box_pack_start(GTK_BOX(pVBox), pImage, FALSE, FALSE, 5);
GtkWidget* pLabel;
pLabel=gtk_label_new("Hello World!!!!!!!!!!!!!!!");
gtk_box_pack_start(GTK_BOX (pVBox), pLabel, FALSE, FALSE, 5);
gtk_box_pack_start(GTK_BOX (hBox), pVBox, FALSE, FALSE, 25);
}
static void hello( GtkWidget *widget, gpointer data ) {
g_print ("Hello World\n");
}
static void callbac (GtkWidget *widget, gpointer data) {
g_print ("Bonjour - %s a été pressé\n", (char *) data);
}
static void event (GdkEvent *event, gpointer data) {
g_print("Bonjour - %s a été pressé\n", (char *) data);
g_print("%d\n",event->key.type);
if(event->key.type==GDK_KEY_PRESS) g_print ("Bonjour - %s a été pressé\n", (char *) data);
}
// vim: sw=4 |
Partager