int svg_to_png(const char* file, const char* dest) { if (!gdk_init_check(NULL, NULL)) { g_warning("Init gdk environment failed"); return -1; } GError* error = NULL; RsvgHandle* handler = rsvg_handle_new_from_file(file, &error); if (error) { g_warning("New RsvgHandle failed: %s", error->message); g_error_free(error); return -1; } GdkPixbuf* pbuf = rsvg_handle_get_pixbuf(handler); g_object_unref(G_OBJECT(handler)); error = NULL; gdk_pixbuf_save(pbuf, dest, "png", &error, NULL); g_object_unref(G_OBJECT(pbuf)); if (error) { g_warning("Save to png file failed: %s", error->message); g_error_free(error); return -1; } return 0; }
static void test_unset_display (void) { if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR)) { GdkDisplayManager *manager; g_unsetenv ("DISPLAY"); g_assert (!gdk_init_check (NULL, NULL)); manager = gdk_display_manager_get (); g_assert (manager != NULL); g_assert (gdk_display_manager_get_default_display (manager) == NULL); exit (0); } g_test_trap_assert_passed (); if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR)) { g_unsetenv ("DISPLAY"); gdk_init (NULL, NULL); exit (0); } g_test_trap_assert_failed (); g_test_trap_assert_stderr ("*cannot open display*"); }
/** * gdk_init: * @argc: (inout): the number of command line arguments. * @argv: (array length=argc) (inout): the array of command line arguments. * * Initializes the GDK library and connects to the windowing system. * If initialization fails, a warning message is output and the application * terminates with a call to `exit(1)`. * * Any arguments used by GDK are removed from the array and @argc and @argv * are updated accordingly. * * GTK+ initializes GDK in gtk_init() and so this function is not usually * needed by GTK+ applications. */ void gdk_init (int *argc, char ***argv) { if (!gdk_init_check (argc, argv)) { const char *display_name = gdk_get_display_arg_name (); g_warning ("cannot open display: %s", display_name ? display_name : ""); exit(1); } }
static gboolean _clutter_backend_gdk_post_parse (ClutterBackend *backend, GError **error) { ClutterBackendGdk *backend_gdk = CLUTTER_BACKEND_GDK (backend); if (_foreign_dpy != NULL) backend_gdk->display = _foreign_dpy; /* Init Gdk, if outside code did not already */ if (!gdk_init_check (NULL, NULL)) return FALSE; /* * Only open connection if not already set by prior call to * clutter_gdk_set_display() */ if (backend_gdk->display == NULL) backend_gdk->display = g_object_ref (gdk_display_get_default ()); g_assert (backend_gdk->display != NULL); #ifdef GDK_WINDOWING_X11 if (GDK_IS_X11_DISPLAY (backend_gdk->display)) { /* Cogl needs to know the Xlib display connection for CoglTexturePixmapX11 */ cogl_xlib_set_display (gdk_x11_display_get_xdisplay (backend_gdk->display)); } #endif backend_gdk->screen = gdk_display_get_default_screen (backend_gdk->display); /* add event filter for Cogl events */ gdk_window_add_filter (NULL, cogl_gdk_filter, NULL); clutter_backend_gdk_init_settings (backend_gdk); CLUTTER_NOTE (BACKEND, "Gdk Display '%s' opened", gdk_display_get_name (backend_gdk->display)); return TRUE; }
int main (int argc, char *argv[]) { //bindtextdomain (GETTEXT_PACKAGE, GNOME_SETTINGS_LOCALEDIR); //bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); //textdomain (GETTEXT_PACKAGE); parse_args (&argc, &argv); gdk_set_allowed_backends ("x11"); if (! gdk_init_check (NULL, NULL)) { g_warning ("Unable to initialize GTK+"); exit (EXIT_FAILURE); } g_log_set_default_handler (gsd_log_default_handler, NULL); if (g_strcmp0(g_getenv("XDG_CURRENT_DESKTOP"), "GNOME")) { xsync = g_slice_new0 (MetaXSync); init_xsync(); mainloop = g_main_loop_new (NULL, FALSE); meta_monitor_manager_initialize (replace); meta_idle_monitor_init_dbus (replace); if (!session_manager_connect ()) g_warning ("Unable to connect to session manager"); register_with_gnome_session (sm_proxy); watch_for_term_signal (); g_main_loop_run (mainloop); g_slice_free(MetaXSync, xsync); } g_debug ("DisplayConfig finished"); return 0; }
static Display* getPluginDisplay() { #if PLATFORM(QT) // At the moment, we only support gdk based plugins (like Flash) that use a different X connection. // The code below has the same effect as this one: // Display *gdkDisplay = gdk_x11_display_get_xdisplay(gdk_display_get_default()); QLibrary library(QLatin1String("libgdk-x11-2.0"), 0); if (!library.load()) return 0; typedef void *(*gdk_init_check_ptr)(void*, void*); gdk_init_check_ptr gdk_init_check = (gdk_init_check_ptr)library.resolve("gdk_init_check"); if (!gdk_init_check) return 0; typedef void *(*gdk_display_get_default_ptr)(); gdk_display_get_default_ptr gdk_display_get_default = (gdk_display_get_default_ptr)library.resolve("gdk_display_get_default"); if (!gdk_display_get_default) return 0; typedef void *(*gdk_x11_display_get_xdisplay_ptr)(void *); gdk_x11_display_get_xdisplay_ptr gdk_x11_display_get_xdisplay = (gdk_x11_display_get_xdisplay_ptr)library.resolve("gdk_x11_display_get_xdisplay"); if (!gdk_x11_display_get_xdisplay) return 0; gdk_init_check(0, 0); return (Display*)gdk_x11_display_get_xdisplay(gdk_display_get_default()); #elif PLATFORM(GTK) // Since we're a gdk/gtk app, we'll (probably?) have the same X connection as any gdk-based // plugins, so we can return that. We might want to add other implementations here later. return GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); #elif PLATFORM(EFL) && defined(HAVE_ECORE_X) return static_cast<Display*>(ecore_x_display_get()); #else return 0; #endif }
static void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { GimpRunMode run_mode = param[0].data.d_int32; GimpPDBStatusType status = GIMP_PDB_SUCCESS; GdkScreen *screen = NULL; gint32 image_ID; static GimpParam values[2]; /* initialize the return of the status */ values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; *nreturn_vals = 1; *return_vals = values; INIT_I18N (); /* how are we running today? */ switch (run_mode) { case GIMP_RUN_INTERACTIVE: /* Possibly retrieve data from a previous run */ gimp_get_data (PLUG_IN_PROC, &shootvals); shootvals.window_id = 0; /* Get information from the dialog */ if (! shoot_dialog (&screen)) status = GIMP_PDB_CANCEL; break; case GIMP_RUN_NONINTERACTIVE: if (nparams == 3) { gboolean do_root = param[1].data.d_int32; shootvals.shoot_type = do_root ? SHOOT_ROOT : SHOOT_WINDOW; shootvals.window_id = param[2].data.d_int32; shootvals.select_delay = 0; } else if (nparams == 7) { shootvals.shoot_type = SHOOT_REGION; shootvals.window_id = param[2].data.d_int32; shootvals.select_delay = 0; shootvals.x1 = param[3].data.d_int32; shootvals.y1 = param[4].data.d_int32; shootvals.x2 = param[5].data.d_int32; shootvals.y2 = param[6].data.d_int32; } else { status = GIMP_PDB_CALLING_ERROR; } if (! gdk_init_check (NULL, NULL)) status = GIMP_PDB_CALLING_ERROR; break; case GIMP_RUN_WITH_LAST_VALS: /* Possibly retrieve data from a previous run */ gimp_get_data (PLUG_IN_PROC, &shootvals); break; default: break; } if (status == GIMP_PDB_SUCCESS) { if (shootvals.select_delay > 0) shoot_delay (shootvals.select_delay); if (shootvals.shoot_type != SHOOT_ROOT && ! shootvals.window_id) { shootvals.window_id = select_window (screen); if (! shootvals.window_id) status = GIMP_PDB_CANCEL; } } if (status == GIMP_PDB_SUCCESS) { image_ID = shoot (screen); if (image_ID == -1) status = GIMP_PDB_EXECUTION_ERROR; } if (status == GIMP_PDB_SUCCESS) { if (run_mode == GIMP_RUN_INTERACTIVE) { /* Store variable states for next run */ gimp_set_data (PLUG_IN_PROC, &shootvals, sizeof (ScreenshotValues)); gimp_display_new (image_ID); } /* set return values */ *nreturn_vals = 2; values[1].type = GIMP_PDB_IMAGE; values[1].data.d_image = image_ID; } values[0].data.d_status = status; }
int main(int argc, char **argv) #endif { char execute[256]; #ifndef GKRELLM_BFM int proximity = 0; int ch; #endif #ifdef FPS int f, o; time_t y; #endif #ifdef PRO int cnt = 25000; #endif #ifndef GKRELLM_BFM GdkEvent *event; #endif #ifdef FPS o = f = y = 0; #endif /* initialize GDK */ #ifndef GKRELLM_BFM if (!gdk_init_check(&argc, &argv)) { fprintf(stderr, "GDK init failed, bye bye. Check \"DISPLAY\" variable.\n"); exit(-1); } #endif gdk_rgb_init(); /* dynamically generate getopt string depending on compile options * we are going to borrow 256 char string from exec function, and * also build up the "compiled features" string */ memset(execute, 0, 256); strcat(execute, "h"); /* help, always in */ #ifdef ENABLE_DUCK strcat(options, "DUCK "); strcat(execute, "d"); #ifdef UPSIDE_DOWN_DUCK strcat(options, "INVERT "); strcat(execute, "u"); #endif /* UPSIDE_DOWN_DUCK */ #endif /* ENABLE_DUCK */ #ifdef ENABLE_CPU strcat(options, "CPU "); strcat(execute, "c"); #endif /* ENABLE_CPU */ #ifdef ENABLE_MEMSCREEN strcat(options, "MEMSCREEN "); strcat(execute, "pmk"); #endif /* ENABLE_MEMSCREEN */ #ifdef ENABLE_FISH strcat(options, "FISH "); strcat(execute, "f"); strcat(execute, "n::"); #endif #ifdef ENABLE_TIME strcat(options, "TIME "); strcat(execute, "t"); #endif #ifndef GKRELLM_BFM /* command line options */ while ((ch = getopt(argc, argv, execute)) != -1) { switch (ch) { #ifdef ENABLE_DUCK case 'd': duck_enabled = 0; break; #ifdef UPSIDE_DOWN_DUCK case 'u': upside_down_duck_enabled = 0; break; #endif /* UPSIDE_DOWN_DUCK */ #endif /* ENABLE_DUCK */ #ifdef ENABLE_CPU case 'c': cpu_enabled = 0; break; #endif /* ENABLE_CPU */ #ifdef ENABLE_MEMSCREEN case 'm': memscreen_enabled = 0; break; case 'p': { /* no sense having -p if memscreen isn't compiled in, right? * what we are going to do is to change the colors as follows: * * (48,140,240) replaced with (158,196,237) - more pale blue * (237,23,23) replaced with (0,255,233) */ unsigned char *p = mem_screen; while (p < mem_screen + sizeof(mem_screen)) if (*p == 48) { /* hopefully no other colors beginning with 48 */ *p++ = 158; *p++ = 196; *p++ = 237; } else if (*p == 237) { /* hopefully no other colors beginning with 237 */ *p++ = 0; *p++ = 255; *p++ = 233; } else p += 3; p = load_screen; while (p < load_screen + sizeof(load_screen)) if (*p == 48) { /* hopefully no other colors beginning with 48 */ *p++ = 158; *p++ = 196; *p++ = 237; } else p += 3; } break; case 'k': memscreen_megabytes = 1; break; #endif /* ENABLE_MEMSCREEN */ #ifdef ENABLE_FISH case 'f': fish_enabled = 0; break; case 'n': fish_traffic = 1; if (optarg) network_interface = optarg; break; #endif #ifdef ENABLE_TIME case 't': time_enabled = 1; break; #endif default: print_usage(); exit(-1); break; } } argc -= optind; argv += optind; #endif /* zero data structure */ memset(&bm, 0, sizeof(bm)); #ifdef __FreeBSD__ if (init_stuff()) exit(-1); #endif /* set default things, from Xresources or compiled-in defaults */ bubblemon_session_defaults(); /* create dockapp window. creates windows, allocates memory, etc */ make_new_bubblemon_dockapp(); #ifdef ENABLE_FISH if(fish_enabled) { prepare_sprites(); } #endif #ifndef GKRELLM_BFM #ifdef PRO while (cnt--) { #else while (1) { #endif while (gdk_events_pending()) { event = gdk_event_get(); if (event) { switch (event->type) { case GDK_DESTROY: gdk_exit(0); exit(0); break; case GDK_BUTTON_PRESS: if (event->button.button == 3) { bm.picture_lock = 1; break; } if (event->button.button <= argc) { snprintf(execute, 250, "%s &", argv[event->button.button - 1]); system(execute); } break; #if defined(ENABLE_CPU) || defined(ENABLE_MEMSCREEN) case GDK_ENTER_NOTIFY: /* mouse in: make it darker, and eventually bring up * meminfo */ proximity = 1; bm.screen_type = get_screen_selection(); bm.picture_lock = 0; break; case GDK_LEAVE_NOTIFY: /* mouse out: back to light */ proximity = 0; break; #endif /* ENABLE_CPU || ENABLE_MEMSCREEN */ default: break; } } } #ifndef PRO usleep(15000); #else /* amazingly enough just calling this function takes insane * amount of time. usleep(0); */ #endif /* get system statistics */ get_memory_load_percentage(); /* update main rgb buffer: bm.rgb_buf */ bubblemon_update(proximity); /* *INDENT-OFF* */ #ifdef FPS /* render frames per second on bottom-right corner :) * This is GCC-specific (functions inside functions) * and very unoptimized. this is obfuscated 'cause its ugly */ f++;{int b;void q(int sx,int sy,int dx,int dy){int i,j;char *from,*to; for(j=0;j<8;j++){from=mem_screen+56*3*(sy+j)+sx*3;to=bm.rgb_buf+56*3* (dy+j)+dx*3;i=12;while(i--)*to++=*from++;}}b=o;if(b>=100){q((b/100)*4, 60,43,46);b=b%100;}q((b/10)*4,60,47,46);q((b%10)*4,60,51,46);}if(time( NULL)!=y){o=f;f=0;y=time(NULL);} #endif /* *INDENT-ON* */ /* actually draw the screen */ #ifndef BLACKBOX gdk_draw_rgb_image(bm.win, bm.gc, 4, 4, 56, 56, GDK_RGB_DITHER_NONE, bm.rgb_buf, 56 * 3); #endif gdk_draw_rgb_image(bm.iconwin, bm.gc, 4, 4, 56, 56, GDK_RGB_DITHER_NONE, bm.rgb_buf, 56 * 3); #ifdef ENABLE_MEMSCREEN /* update graph histories */ if (memscreen_enabled) roll_history(); #endif /* ENABLE_MEMSCREEN */ } #endif return 0; } /* main */
int main (int argc, char *argv[]) { /* a pointer to a window object - this is what we will draw on. */ GdkWindow *window; /* a set of "attributes" for our windows. This struct holds things * like width, height etc. */ GdkWindowAttr attributes; /* a bitmask of the attributes you actually want to read out of the * attributes thing above */ gint attributes_mask; /* GDK apps need a main loop to wait for events and so forth. This main * loop has a struct which tells you about it called "GMainLoop". We need * one of them. */ GMainLoop *mainloop; /* initialise gdk. We pass in argc and argv - it uses them for info like * display on X and so forth. Die if GDK can't initialize. * * Always initialise gdk before working with it. Stuff breaks otherwise. */ if (!gdk_init_check (&argc, &argv)) { return FALSE; } /* gdk_rgb_init() is a function which I can only guess sets up the * true colour colour map. It returns void so we can't check its * return value. */ gdk_rgb_init(); /* set the attributes for the window. Lets create a 400x400 top-level * window. */ attributes.window_type = GDK_WINDOW_TOPLEVEL; attributes.width = 400; attributes.height = 400; attributes.wclass = GDK_INPUT_OUTPUT; /* Get a true-colour colour map. GDK also supports indexed colour maps * but they aren't so interesting for us. */ attributes.colormap = gdk_rgb_get_cmap (); /* set our mask so that the "colormap" element is used. */ attributes_mask = GDK_WA_COLORMAP; /* create the window. */ window = gdk_window_new (NULL, &attributes, attributes_mask); /* show the window. */ gdk_window_show (window); /* Create a new main loop object. The True is to say that the structure * should be initialised to say that it is running. */ mainloop = g_main_new (TRUE); /* Run that main loop */ g_main_run (mainloop); }