static void createBrowserWindow(const gchar *uri, WebKitSettings *webkitSettings, gboolean shouldLoadSession) { GtkWidget *webView = webkit_web_view_new(); if (editorMode) webkit_web_view_set_editable(WEBKIT_WEB_VIEW(webView), TRUE); GtkWidget *mainWindow = browser_window_new(WEBKIT_WEB_VIEW(webView), NULL); if (backgroundColor) browser_window_set_background_color(BROWSER_WINDOW(mainWindow), backgroundColor); if (geometry) gtk_window_parse_geometry(GTK_WINDOW(mainWindow), geometry); if (webkitSettings) webkit_web_view_set_settings(WEBKIT_WEB_VIEW(webView), webkitSettings); if (!editorMode) { if (shouldLoadSession && sessionFile) browser_window_load_session(BROWSER_WINDOW(mainWindow), sessionFile); else { gchar *url = argumentToURL(uri); browser_window_load_uri(BROWSER_WINDOW(mainWindow), url); g_free(url); } } gtk_widget_grab_focus(webView); gtk_widget_show(mainWindow); }
static void show_hist_window() { gtk_window_parse_geometry(GTK_WINDOW(hist_window),geomstr); update_hist_button(); gtk_window_resize(GTK_WINDOW(hist_window), 1, 1); gtk_widget_show (hist_window); gtk_window_present(GTK_WINDOW(hist_window)); }
int main (int argc, char *argv[]) { GtkWidget *window; GtkWidget *darea; GError *error; int i; rgba_t bgcolor1, bgcolor2; error = NULL; gtk_init_with_args (&argc, &argv, "circlesaver", options, NULL, &error); window = gs_theme_window_new(); darea = gtk_drawing_area_new(); gtk_container_add(GTK_CONTAINER (window), darea); g_signal_connect(darea, "expose-event", G_CALLBACK (on_expose_event), NULL); g_signal_connect(window, "destroy", G_CALLBACK (gtk_main_quit), NULL); for (i = 0; i < NUM_CIRCLES; ++i) { circles[i] = gen_circle(i); } bgcolor1 = color(0xFF000000); bgcolor2 = color(0xFF705391); bgpattern = cairo_pattern_create_linear(100.5, 0.0, 100.5, 500.0); cairo_pattern_add_color_stop_rgb(bgpattern, 0.0, bgcolor1.r, bgcolor1.g, bgcolor1.b); cairo_pattern_add_color_stop_rgb(bgpattern, 1.0, bgcolor2.r, bgcolor2.g, bgcolor2.b); g_timeout_add_full (G_PRIORITY_HIGH, UPDATE_FREQ, timeout_callback, darea, NULL); //g_timeout_add (UPDATE_FREQ, timeout_callback, darea); if ((geometry == NULL) || !gtk_window_parse_geometry (GTK_WINDOW (window), geometry)) gtk_window_set_default_size (GTK_WINDOW (window), 640, 480); gtk_widget_show_all(window); gtk_main(); cairo_pattern_destroy(bgpattern); return 0; }
int main(int argc, char *argv[]) { Chart_app *app; GError *error = NULL; prog_name = argv[0]; if (strrchr(prog_name, '/')) prog_name = strrchr(prog_name, '/') + 1; if (!gtk_init_with_args(&argc, &argv, NULL, option_entries, NULL, &error)) { g_printerr("%s\n", error->message); g_error_free (error); return EXIT_FAILURE; } app = chart_app_new(); app->frame = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(app->frame), "Stripchart"); gtk_window_set_default_size(GTK_WINDOW(app->frame), 360, 50); if (geometry) gtk_window_parse_geometry(GTK_WINDOW(app->frame), geometry); gtk_widget_show(app->frame); g_signal_connect(GTK_OBJECT(app->frame), "destroy", G_CALLBACK(gtk_main_quit), NULL); gtk_container_add(GTK_CONTAINER(app->frame), app->hbox); gtk_widget_add_events(app->strip, GDK_BUTTON_PRESS_MASK); g_signal_connect(GTK_OBJECT(app->frame), "button-press-event", G_CALLBACK(on_button_press), app); g_signal_connect(GTK_OBJECT(app->frame), "popup-menu", G_CALLBACK(on_popup_menu), app); gtk_main(); return EXIT_SUCCESS; }
JNIEXPORT jboolean JNICALL Java_org_gnome_gtk_GtkWindow_gtk_1window_1parse_1geometry ( JNIEnv* env, jclass cls, jlong _self, jstring _geometry ) { gboolean result; jboolean _result; GtkWindow* self; const gchar* geometry; // convert parameter self self = (GtkWindow*) _self; // convert parameter geometry geometry = (const gchar*) bindings_java_getString(env, _geometry); if (geometry == NULL) { return JNI_FALSE; // Java Exception already thrown } // call function result = gtk_window_parse_geometry(self, geometry); // cleanup parameter self // cleanup parameter geometry bindings_java_releaseString(geometry); // translate return value to JNI type _result = (jboolean) result; // and finally return _result; }
/** * gimp_session_info_apply_geometry: * @info: * @screen: * @current_monitor: * * Apply the geometry stored in the session info object to the * associated widget. **/ void gimp_session_info_apply_geometry (GimpSessionInfo *info, GdkScreen *screen, gint current_monitor, gboolean apply_stored_monitor) { GdkRectangle rect; GdkRectangle work_rect; gchar geom[32]; gint monitor; gint width; gint height; g_return_if_fail (GIMP_IS_SESSION_INFO (info)); g_return_if_fail (GTK_IS_WINDOW (info->p->widget)); g_return_if_fail (GDK_IS_SCREEN (screen)); monitor = current_monitor; if (apply_stored_monitor) { gint n_monitors; n_monitors = gdk_screen_get_n_monitors (screen); if (info->p->monitor != DEFAULT_MONITOR && info->p->monitor < n_monitors) { monitor = info->p->monitor; } else { monitor = gdk_screen_get_primary_monitor (screen); } } gdk_screen_get_monitor_geometry (screen, monitor, &rect); gdk_screen_get_monitor_workarea (screen, monitor, &work_rect); info->p->x += rect.x; info->p->y += rect.y; if (gimp_session_info_get_remember_size (info) && info->p->width > 0 && info->p->height > 0) { width = info->p->width; height = info->p->height; } else { GtkRequisition requisition; gtk_widget_size_request (info->p->widget, &requisition); width = requisition.width; height = requisition.height; } info->p->x = CLAMP (info->p->x, work_rect.x, work_rect.x + work_rect.width - width); info->p->y = CLAMP (info->p->y, work_rect.y, work_rect.y + work_rect.height - height); if (info->p->right_align && info->p->bottom_align) { g_strlcpy (geom, "-0-0", sizeof (geom)); } else if (info->p->right_align) { g_snprintf (geom, sizeof (geom), "-0%+d", info->p->y); } else if (info->p->bottom_align) { g_snprintf (geom, sizeof (geom), "%+d-0", info->p->x); } else { g_snprintf (geom, sizeof (geom), "%+d%+d", info->p->x, info->p->y); } gtk_window_parse_geometry (GTK_WINDOW (info->p->widget), geom); if (gimp_session_info_get_remember_size (info) && info->p->width > 0 && info->p->height > 0) { gtk_window_set_default_size (GTK_WINDOW (info->p->widget), info->p->width, info->p->height); } /* Window managers and windowing systems suck. They have their own * ideas about WM standards and when it's appropriate to honor * user/application-set window positions and when not. Therefore, * use brute force and "manually" position dialogs whenever they * are shown. This is important especially for transient dialogs, * because window managers behave even "smarter" then... */ if (GTK_IS_DIALOG (info->p->widget)) g_signal_connect (info->p->widget, "show", G_CALLBACK (gimp_session_info_dialog_show), info); }
void gcb_main() { GtkWidget *hbox,*vbox; int i; #if 1 if (gcb_enabled==old_gcb_enabled && gcb_position==old_gcb_position && gcb_position_x==old_gcb_position_x && gcb_position_y==old_gcb_position_y) return; #endif old_gcb_enabled = gcb_enabled; old_gcb_position = gcb_position; old_gcb_position_x = gcb_position_x; old_gcb_position_y = gcb_position_y; if (mainwin) { gtk_widget_destroy(mainwin); mainwin = NULL; } #if 0 if (button_bar_tips) gtk_widget_destroy(button_bar_tips); #endif if (hist_window) { gtk_widget_destroy(hist_window); hist_window = NULL; } if (!gcb_enabled) return; // printf("gcb_position:%d\n", gcb_position); static char geo[][2]={{0,0},{'+','-'},{'+','+'},{'-','-'},{'-','+'}}; g_free(geomstr); geomstr = g_strdup_printf("%c%d%c%d", geo[gcb_position][0], gcb_position_x, geo[gcb_position][1], gcb_position_y); dbg("geomstr %s\n", geomstr); if (!buttonArr) { buttonArr=(GtkWidget**)g_malloc(gcb_button_n * sizeof(GtkWidget *)); buttonStr=(gchar**)g_malloc0(gcb_button_n * sizeof(gchar *)); } if (!hist_strArr) { hist_strArr=(gchar**)g_malloc0(gcb_history_n * sizeof(gchar *)); hist_buttonArr=(GtkWidget**)g_malloc(gcb_history_n * sizeof(GtkWidget *)); } mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_has_resize_grip(GTK_WINDOW(mainwin), FALSE); gtk_window_set_decorated(GTK_WINDOW(mainwin),FALSE); gtk_window_set_focus_on_map (GTK_WINDOW(mainwin), FALSE); hist_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_has_resize_grip(GTK_WINDOW(hist_window), FALSE); char icon_path[40]; sys_icon_fname("gcb.png", icon_path); GtkWidget *win_icon=gtk_image_new_from_file(icon_path); gtk_window_set_icon(GTK_WINDOW(mainwin), gtk_image_get_pixbuf(GTK_IMAGE(win_icon))); gtk_window_set_icon(GTK_WINDOW(hist_window), gtk_image_get_pixbuf(GTK_IMAGE(win_icon))); // Under gnome 2.0, the mainwin is not fixed if decorated, annoying gtk_window_set_decorated(GTK_WINDOW(hist_window),FALSE); gtk_window_set_skip_pager_hint(GTK_WINDOW(hist_window),TRUE); gtk_window_set_skip_taskbar_hint(GTK_WINDOW(hist_window),TRUE); gtk_window_set_title (GTK_WINDOW (hist_window),"gcb history"); gtk_window_set_title (GTK_WINDOW(mainwin), "gcb: gtk copy-paste buffer"); gtk_window_stick(GTK_WINDOW(mainwin)); // g_signal_connect(G_OBJECT (mainwin),"destroy", G_CALLBACK (do_exit), NULL); g_signal_connect(G_OBJECT (hist_window),"delete_event", G_CALLBACK (delete_hist_win), NULL); g_signal_connect(G_OBJECT (hist_window),"focus-out-event", G_CALLBACK (hist_focus_out_callback), NULL); #if !GTK_CHECK_VERSION(2,12,0) button_bar_tips = gtk_tooltips_new (); #endif hbox = gtk_hbox_new (FALSE, 1); gtk_container_add (GTK_CONTAINER(mainwin), hbox); gtk_window_parse_geometry(GTK_WINDOW(mainwin),geomstr); for(i=0;i<gcb_button_n;i++) { buttonArr[i] = gtk_button_new_with_label ("---"); // gtk_container_set_border_width(GTK_CONTAINER(buttonArr[i]),0); gtk_box_pack_start (GTK_BOX(hbox), buttonArr[i], TRUE, TRUE, FALSE); gtk_widget_show (buttonArr[i]); g_signal_connect (G_OBJECT (buttonArr[i]), "button-press-event", G_CALLBACK (get_mouse_button), (gpointer) buttonArr[i]); #if 0 g_signal_connect (G_OBJECT (buttonArr[i]), "key-press-event", G_CALLBACK (key_press_event), NULL); #endif #if 1 g_signal_connect (G_OBJECT (buttonArr[i]), "scroll-event", G_CALLBACK (gcb_button_scroll_event), NULL); #endif } vbox = gtk_vbox_new (FALSE, 1); gtk_orientable_set_orientation(GTK_ORIENTABLE(vbox), GTK_ORIENTATION_VERTICAL); gtk_container_add (GTK_CONTAINER(hist_window), vbox); for(i=0;i<gcb_history_n;i++) { hist_buttonArr[i] = gtk_button_new_with_label ("---"); gtk_container_set_border_width(GTK_CONTAINER(hist_buttonArr[i]),0); gtk_box_pack_start (GTK_BOX(vbox), hist_buttonArr[i], TRUE, TRUE, FALSE); gtk_widget_show (hist_buttonArr[i]); g_signal_connect (G_OBJECT (hist_buttonArr[i]), "button-press-event", G_CALLBACK (hist_get_mouse_button), (gpointer) hist_buttonArr[i]); #if 1 g_signal_connect (G_OBJECT (hist_buttonArr[i]), "key-press-event", G_CALLBACK (hist_key_press_event), NULL); #endif } #if 1 // need this because on win32 scoll is not recieved if win is not focused. gtk_box_pack_start (GTK_BOX (hbox), gtk_vseparator_new(), FALSE, FALSE, 0); GtkWidget *eve_arrow = gtk_event_box_new(); gtk_event_box_set_visible_window (GTK_EVENT_BOX(eve_arrow), FALSE); gtk_box_pack_start (GTK_BOX(hbox), eve_arrow, FALSE, FALSE, FALSE); g_signal_connect(G_OBJECT(eve_arrow),"button-press-event", G_CALLBACK(mouse_button_callback), NULL); gtk_container_add(GTK_CONTAINER(eve_arrow), gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_IN)); #endif gtk_widget_show_all(hbox); gtk_widget_show (vbox); gtk_widget_show (mainwin); pclipboard_prim = gtk_clipboard_get(GDK_SELECTION_PRIMARY); pclipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); set_snoop_button(buttonArr[0]); get_selection(pclipboard); get_selection(pclipboard_prim); gtk_container_set_border_width(GTK_CONTAINER(hbox),0); gtk_container_set_border_width(GTK_CONTAINER(mainwin),0); gtk_window_parse_geometry(GTK_WINDOW(mainwin),geomstr); #if GTK_CHECK_VERSION(2,6,0) g_signal_connect(pclipboard, "owner-change", G_CALLBACK (cb_owner_change), NULL); g_signal_connect(pclipboard_prim, "owner-change", G_CALLBACK (cb_owner_change), NULL); #endif }
static void gedit_main_window (void) { GSList *file_list; GeditWindow *window; GeditCommandLine *command_line; GeditApp *app; gboolean doc_created = FALSE; const gchar *geometry; app = gedit_app_get_default (); gedit_debug_message (DEBUG_APP, "Create main window"); window = gedit_app_create_window (app, NULL); command_line = gedit_command_line_get_default (); file_list = gedit_command_line_get_file_list (command_line); if (file_list != NULL) { GSList *loaded; const GeditEncoding *encoding; gint line_position; gint column_position; encoding = gedit_command_line_get_encoding (command_line); line_position = gedit_command_line_get_line_position (command_line); column_position = gedit_command_line_get_column_position (command_line); gedit_debug_message (DEBUG_APP, "Load files"); loaded = _gedit_cmd_load_files_from_prompt (window, file_list, encoding, line_position, column_position); doc_created = loaded != NULL; g_slist_free (loaded); } if (gedit_utils_can_read_from_stdin ()) { doc_created = gedit_main_load_from_stdin (window, !doc_created); } if (!doc_created || gedit_command_line_get_new_document (command_line)) { gedit_debug_message (DEBUG_APP, "Create tab"); gedit_window_create_tab (window, TRUE); } geometry = gedit_command_line_get_geometry (command_line); gedit_debug_message (DEBUG_APP, "Show window"); gtk_widget_show (GTK_WIDGET (window)); if (geometry) { gtk_window_parse_geometry (GTK_WINDOW (window), geometry); } }
gint yad_print_run (void) { GtkWidget *dlg; GtkWidget *box, *img, *lbl; gchar *uri, *job_name = NULL; GtkPrintCapabilities pcap; GtkPrintOperationAction act = GTK_PRINT_OPERATION_ACTION_PRINT; gint resp, ret = 0; GError *err = NULL; /* check if file is exists */ if (options.common_data.uri && options.common_data.uri[0]) { if (!g_file_test (options.common_data.uri, G_FILE_TEST_EXISTS)) { g_printerr (_("File %s not found.\n"), options.common_data.uri); return 1; } } else { g_printerr (_("Filename is not specified.\n")); return 1; } /* create print dialog */ dlg = gtk_print_unix_dialog_new (options.data.dialog_title, NULL); gtk_window_set_type_hint (GTK_WINDOW (dlg), GDK_WINDOW_TYPE_HINT_NORMAL); gtk_print_unix_dialog_set_embed_page_setup (GTK_PRINT_UNIX_DIALOG (dlg), TRUE); pcap = GTK_PRINT_CAPABILITY_PAGE_SET | GTK_PRINT_CAPABILITY_COPIES | GTK_PRINT_CAPABILITY_COLLATE | GTK_PRINT_CAPABILITY_REVERSE | GTK_PRINT_CAPABILITY_NUMBER_UP | GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT; if (options.common_data.preview && options.print_data.type != YAD_PRINT_RAW) pcap |= GTK_PRINT_CAPABILITY_PREVIEW; gtk_print_unix_dialog_set_manual_capabilities (GTK_PRINT_UNIX_DIALOG (dlg), pcap); if (!settings.print_settings) settings.print_settings = gtk_print_unix_dialog_get_settings (GTK_PRINT_UNIX_DIALOG (dlg)); uri = g_build_filename (g_get_current_dir (), "yad.pdf", NULL); gtk_print_settings_set (settings.print_settings, "output-uri", g_filename_to_uri (uri, NULL, NULL)); g_free (uri); gtk_print_unix_dialog_set_settings (GTK_PRINT_UNIX_DIALOG (dlg), settings.print_settings); if (settings.page_setup) gtk_print_unix_dialog_set_page_setup (GTK_PRINT_UNIX_DIALOG (dlg), settings.page_setup); /* set window behavior */ gtk_widget_set_name (dlg, "yad-dialog-window"); if (options.data.sticky) gtk_window_stick (GTK_WINDOW (dlg)); gtk_window_set_resizable (GTK_WINDOW (dlg), !options.data.fixed); gtk_window_set_keep_above (GTK_WINDOW (dlg), options.data.ontop); gtk_window_set_decorated (GTK_WINDOW (dlg), !options.data.undecorated); gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dlg), options.data.skip_taskbar); gtk_window_set_skip_pager_hint (GTK_WINDOW (dlg), options.data.skip_taskbar); /* set window size and position */ if (!options.data.geometry) { gtk_window_set_default_size (GTK_WINDOW (dlg), options.data.width, options.data.height); if (options.data.center) gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_CENTER); else if (options.data.mouse) gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_MOUSE); } else { /* parse geometry, if given. must be after showing widget */ gtk_widget_realize (dlg); gtk_window_parse_geometry (GTK_WINDOW (dlg), options.data.geometry); } /* create yad's top box */ if (options.data.dialog_text || options.data.dialog_image) { #if !GTK_CHECK_VERSION(3,0,0) box = gtk_hbox_new (FALSE, 0); #else box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); #endif if (options.data.dialog_image) { GdkPixbuf *pb = NULL; pb = get_pixbuf (options.data.dialog_image, YAD_BIG_ICON); img = gtk_image_new_from_pixbuf (pb); if (pb) g_object_unref (pb); gtk_widget_set_name (img, "yad-dialog-image"); gtk_box_pack_start (GTK_BOX (box), img, FALSE, FALSE, 2); } if (options.data.dialog_text) { gchar *buf = g_strcompress (options.data.dialog_text); lbl = gtk_label_new (NULL); if (!options.data.no_markup) gtk_label_set_markup (GTK_LABEL (lbl), buf); else gtk_label_set_text (GTK_LABEL (lbl), buf); gtk_widget_set_name (lbl, "yad-dialog-label"); gtk_label_set_selectable (GTK_LABEL (lbl), options.data.selectable_labels); gtk_misc_set_alignment (GTK_MISC (lbl), options.data.text_align, 0.5); if (options.data.geometry || options.data.width != -1) gtk_label_set_line_wrap (GTK_LABEL (lbl), TRUE); gtk_box_pack_start (GTK_BOX (box), lbl, TRUE, TRUE, 2); g_signal_connect (G_OBJECT (lbl), "size-allocate", G_CALLBACK (size_allocate_cb), NULL); g_free (buf); } /* add tob box to dialog */ gtk_widget_show_all (box); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), box, TRUE, TRUE, 5); gtk_box_reorder_child (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), box, 0); } do { resp = gtk_dialog_run (GTK_DIALOG (dlg)); switch (resp) { case GTK_RESPONSE_APPLY: /* ask for preview */ act = GTK_PRINT_OPERATION_ACTION_PREVIEW; case GTK_RESPONSE_OK: /* run print */ settings.print_settings = gtk_print_unix_dialog_get_settings (GTK_PRINT_UNIX_DIALOG (dlg)); settings.page_setup = gtk_print_unix_dialog_get_page_setup (GTK_PRINT_UNIX_DIALOG (dlg)); job_name = g_strdup_printf ("yad-%s-%d", g_path_get_basename (options.common_data.uri), getpid ()); if (options.print_data.type != YAD_PRINT_RAW) { /* print text or image */ GtkPrintOperation *op = gtk_print_operation_new (); gtk_print_operation_set_unit (op, GTK_UNIT_POINTS); gtk_print_operation_set_print_settings (op, settings.print_settings); gtk_print_operation_set_default_page_setup (op, settings.page_setup); gtk_print_operation_set_job_name (op, job_name); switch (options.print_data.type) { case YAD_PRINT_TEXT: g_signal_connect (G_OBJECT (op), "begin-print", G_CALLBACK (begin_print_text), NULL); g_signal_connect (G_OBJECT (op), "draw-page", G_CALLBACK (draw_page_text), NULL); break; case YAD_PRINT_IMAGE: gtk_print_operation_set_n_pages (op, 1); g_signal_connect (G_OBJECT (op), "draw-page", G_CALLBACK (draw_page_image), NULL); break; default:; } if (gtk_print_operation_run (op, act, NULL, &err) == GTK_PRINT_OPERATION_RESULT_ERROR) { g_printerr (_("Printing failed: %s\n"), err->message); ret = 1; } } else { /* print raw ps or pdf data */ GtkPrinter *prnt; GtkPrintJob *job; prnt = gtk_print_unix_dialog_get_selected_printer (GTK_PRINT_UNIX_DIALOG (dlg)); if (g_str_has_suffix (options.common_data.uri, ".ps")) { if (!gtk_printer_accepts_ps (prnt)) { g_printerr (_("Printer doesn't support ps format.\n")); ret = 1; } } else if (g_str_has_suffix (options.common_data.uri, ".pdf")) { if (!gtk_printer_accepts_pdf (prnt)) { g_printerr (_("Printer doesn't support pdf format.\n")); ret = 1; } } else { g_printerr (_("This file type is not supported for raw printing.\n")); ret = 1; } if (ret == 1) break; job = gtk_print_job_new (job_name, prnt, settings.print_settings, settings.page_setup); if (gtk_print_job_set_source_file (job, options.common_data.uri, &err)) { gtk_print_job_send (job, (GtkPrintJobCompleteFunc) raw_print_done, &ret, NULL); gtk_main (); } else { g_printerr (_("Load source file failed: %s\n"), err->message); ret = 1; } } break; default: ret = 1; break; } } while (resp == GTK_RESPONSE_APPLY); gtk_widget_destroy (dlg); write_settings (); return ret; }
static void open_files (GApplication *application, gboolean new_window, gboolean new_document, gchar *geometry, gint line_position, gint column_position, const GtkSourceEncoding *encoding, GInputStream *stdin_stream, GSList *file_list, GApplicationCommandLine *command_line) { GeditWindow *window = NULL; GeditTab *tab; gboolean doc_created = FALSE; if (!new_window) { window = get_active_window (GTK_APPLICATION (application)); } if (window == NULL) { gedit_debug_message (DEBUG_APP, "Create main window"); window = gedit_app_create_window (GEDIT_APP (application), NULL); gedit_debug_message (DEBUG_APP, "Show window"); gtk_widget_show (GTK_WIDGET (window)); } if (geometry) { gtk_window_parse_geometry (GTK_WINDOW (window), geometry); } if (stdin_stream) { gedit_debug_message (DEBUG_APP, "Load stdin"); tab = gedit_window_create_tab_from_stream (window, stdin_stream, encoding, line_position, column_position, TRUE); doc_created = tab != NULL; if (doc_created && command_line) { set_command_line_wait (GEDIT_APP (application), tab); } g_input_stream_close (stdin_stream, NULL, NULL); } if (file_list != NULL) { GSList *loaded; gedit_debug_message (DEBUG_APP, "Load files"); loaded = _gedit_cmd_load_files_from_prompt (window, file_list, encoding, line_position, column_position); doc_created = doc_created || loaded != NULL; if (command_line) { g_slist_foreach (loaded, (GFunc)set_command_line_wait_doc, GEDIT_APP (application)); } g_slist_free (loaded); } if (!doc_created || new_document) { gedit_debug_message (DEBUG_APP, "Create tab"); tab = gedit_window_create_tab (window, TRUE); if (command_line) { set_command_line_wait (GEDIT_APP (application), tab); } } gtk_window_present (GTK_WINDOW (window)); }
int main(int argc, char **argv) { GtkWidget *win; GError *error = NULL; GtkApplication *application; gchar *locale_dir; gint retval; locale_dir = ghex_locale_dir (); bindtextdomain (GETTEXT_PACKAGE, locale_dir); g_free (locale_dir); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* Initialize GTK+ program */ if (!gtk_init_with_args (&argc, &argv, _("- GTK+ binary editor"), options, GETTEXT_PACKAGE, &error)) { g_printerr (_("%s\nRun '%s --help' to see a full list of available command line options.\n"), error->message, argv[0]); g_error_free (error); return 1; } /* Set default window icon */ gtk_window_set_default_icon_name ("ghex"); /* load preferences */ ghex_init_configuration(); /* accessibility setup */ setup_factory(); application = gtk_application_new ("org.gnome.GHexApplication", G_APPLICATION_NON_UNIQUE); g_signal_connect (application, "activate", G_CALLBACK (ghex_activate), NULL); g_application_register (G_APPLICATION (application), NULL, NULL); if (args_remaining != NULL) { gchar **filename; for (filename = args_remaining; *filename != NULL; filename++) { if (g_file_test (*filename, G_FILE_TEST_EXISTS)) { win = ghex_window_new_from_file (application, *filename); if(win != NULL) { if(geometry) { if(!gtk_window_parse_geometry(GTK_WINDOW(win), geometry)) g_warning(_("Invalid geometry string \"%s\"\n"), geometry); geometry = NULL; } gtk_widget_show(win); } } } } if(ghex_window_get_list() == NULL) { win = ghex_window_new (application); if(geometry) { if(!gtk_window_parse_geometry(GTK_WINDOW(win), geometry)) g_warning(_("Invalid geometry string \"%s\"\n"), geometry); geometry = NULL; } gtk_widget_show(win); } else win = GTK_WIDGET(ghex_window_get_list()->data); retval = g_application_run (G_APPLICATION (application), argc, argv); g_object_unref (application); return retval; }
void app_new(int argc, char *argv[], const char *geometry_string) { GtkWidget *vbox; GtkWidget *widget; GtkWidget *vpane; GtkWidget *separator; GtkLabel *filler; GtkHBox *labels; GtkVBox *status_vbox; GtkStatusbar *grip; app_window = gnome_app_new(GTT_APP_NAME, GTT_APP_TITLE " " VERSION); gtk_window_set_wmclass(GTK_WINDOW(app_window), GTT_APP_NAME, GTT_APP_PROPER_NAME); /* 485 x 272 seems to be a good size to default to */ gtk_window_set_default_size(GTK_WINDOW(app_window), 485, 272); gtk_window_set_resizable (GTK_WINDOW(app_window), TRUE); /* build menus */ menus_create(GNOME_APP(app_window)); /* build toolbar */ widget = build_toolbar(); gtk_widget_show(widget); gnome_app_set_toolbar(GNOME_APP(app_window), GTK_TOOLBAR(widget)); /* container holds status bar, main ctree widget */ vbox = gtk_vbox_new(FALSE, 0); /* build statusbar */ status_vbox = GTK_VBOX(gtk_vbox_new(FALSE, 0)); gtk_widget_show(GTK_WIDGET(status_vbox)); labels = GTK_HBOX(gtk_hbox_new(FALSE, 0)); gtk_widget_show(GTK_WIDGET(labels)); status_bar = gtk_hbox_new(FALSE, 0); gtk_widget_show(status_bar); separator = gtk_hseparator_new(); gtk_widget_show(separator); gtk_box_pack_start(GTK_BOX(status_vbox), separator, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(status_vbox), GTK_WIDGET (labels), TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(status_bar), GTK_WIDGET (status_vbox), TRUE, TRUE, 0); grip = GTK_STATUSBAR(gtk_statusbar_new()); gtk_statusbar_set_has_resize_grip(grip, TRUE); gtk_widget_show(GTK_WIDGET(grip)); gtk_box_pack_start(GTK_BOX(status_bar), GTK_WIDGET(grip), FALSE, FALSE, 0); /* put elapsed time into statusbar */ status_day_time = GTK_LABEL(gtk_label_new(_("00:00"))); gtk_widget_show(GTK_WIDGET(status_day_time)); gtk_box_pack_start(GTK_BOX(labels), GTK_WIDGET(status_day_time), FALSE, TRUE, 0); /* put project name into statusbar */ status_project = GTK_LABEL(gtk_label_new( _("Timer is not running"))); gtk_widget_show(GTK_WIDGET(status_project)); gtk_box_pack_start(GTK_BOX(labels), GTK_WIDGET(status_project), FALSE, TRUE, 10); filler = GTK_LABEL(gtk_label_new("")); gtk_widget_show(GTK_WIDGET(filler)); gtk_box_pack_start(GTK_BOX(labels), GTK_WIDGET(filler), TRUE, TRUE, 1); /* put timer icon into statusbar */ status_timer = gtk_image_new_from_stock (GNOME_STOCK_TIMER, GTK_ICON_SIZE_MENU); gtk_widget_show(status_timer); gtk_box_pack_end(GTK_BOX(status_bar), GTK_WIDGET(status_timer), FALSE, FALSE, 1); /* create the main columned tree for showing projects */ projects_tree = gtt_projects_tree_new (); g_signal_connect (projects_tree, "columns-setup-done", G_CALLBACK (projects_tree_columns_setup_done), NULL); gtk_tree_view_set_reorderable (GTK_TREE_VIEW (projects_tree), TRUE); g_signal_connect (projects_tree, "row-activated", G_CALLBACK (projects_tree_row_activated), NULL); /* create the notes area */ global_na = notes_area_new(); vpane = notes_area_get_widget (global_na); /* Need to reparent, to get rid of glade parent-window hack. * But gtk_widget_reparent (vpane); causes a "Gtk-CRITICAL" * to occur. So we need a fancier move. */ gtk_widget_ref (vpane); gtk_container_remove(GTK_CONTAINER(vpane->parent), vpane); gtk_box_pack_start(GTK_BOX(vbox), vpane, TRUE, TRUE, 0); gtk_widget_unref (vpane); gtk_box_pack_end(GTK_BOX(vbox), status_bar, FALSE, FALSE, 2); notes_area_add_projects_tree (global_na, projects_tree); /* we are done building it, make it visible */ gtk_widget_show(vbox); gnome_app_set_contents(GNOME_APP(app_window), vbox); gtt_status_icon_create(); if (!geometry_string) return; if (gtk_window_parse_geometry(GTK_WINDOW(app_window),geometry_string)) { geom_size_override=TRUE; } else { gnome_app_error(GNOME_APP(app_window), _("Couldn't understand geometry (position and size)\n" " specified on command line")); } }
GtkWidget * create_dialog (void) { GtkWidget *dlg; GtkWidget *hbox, *vbox, *hbox2, *bbox; GtkWidget *image; GtkWidget *text; GtkWidget *main_widget = NULL; GtkWidget *topb = NULL; /* create dialog window */ dlg = gtk_dialog_new (); if (options.data.splash) gtk_window_set_type_hint (GTK_WINDOW (dlg), GDK_WINDOW_TYPE_HINT_SPLASHSCREEN); else gtk_window_set_type_hint (GTK_WINDOW (dlg), GDK_WINDOW_TYPE_HINT_NORMAL); gtk_window_set_title (GTK_WINDOW (dlg), options.data.dialog_title); gtk_widget_set_name (dlg, "yad-dialog-window"); #ifndef G_OS_WIN32 if (options.parent) { gdk_window_set_transient_for (gtk_widget_get_window (dlg), gdk_x11_window_foreign_new_for_display (gdk_display_get_default (), options.parent)); } #endif if (options.data.no_escape) g_signal_connect (G_OBJECT (dlg), "close", G_CALLBACK (ignore_close_cb) , NULL); /* get buttons container */ bbox = gtk_dialog_get_action_area (GTK_DIALOG (dlg)); /* set window icon */ if (options.data.window_icon) { if (g_file_test (options.data.window_icon, G_FILE_TEST_EXISTS)) gtk_window_set_icon_from_file (GTK_WINDOW (dlg), options.data.window_icon, NULL); else gtk_window_set_icon_name (GTK_WINDOW (dlg), options.data.window_icon); } /* set window borders */ if (options.data.borders == -1) options.data.borders = (gint) gtk_container_get_border_width (GTK_CONTAINER (dlg)); gtk_container_set_border_width (GTK_CONTAINER (dlg), (guint) options.data.borders); /* set window size and position */ if (!options.data.geometry && !options.data.maximized && !options.data.fullscreen) { gtk_window_set_default_size (GTK_WINDOW (dlg), options.data.width, options.data.height); if (options.data.center) gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_CENTER); else if (options.data.mouse) gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_MOUSE); } /* set window behavior */ if (options.data.sticky) gtk_window_stick (GTK_WINDOW (dlg)); gtk_window_set_keep_above (GTK_WINDOW (dlg), options.data.ontop); gtk_window_set_decorated (GTK_WINDOW (dlg), !options.data.undecorated); gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dlg), options.data.skip_taskbar); gtk_window_set_skip_pager_hint (GTK_WINDOW (dlg), options.data.skip_taskbar); /* create timeout indicator widget */ if (options.data.timeout) { if (G_LIKELY (options.data.to_indicator) && g_ascii_strcasecmp (options.data.to_indicator, "none")) { topb = gtk_progress_bar_new (); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (topb), 1.0); gtk_widget_set_name (topb, "yad-timeout-indicator"); } } /* add top label widgets */ #if !GTK_CHECK_VERSION(3,0,0) hbox = hbox2 = gtk_hbox_new (FALSE, 0); #else hbox = hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); #endif gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), hbox, TRUE, TRUE, 5); #if !GTK_CHECK_VERSION(3,0,0) vbox = gtk_vbox_new (FALSE, 0); #else vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); #endif /* add timeout indicator */ if (topb) { if (g_ascii_strcasecmp (options.data.to_indicator, "top") == 0) { #if !GTK_CHECK_VERSION(3,0,0) gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (topb), GTK_PROGRESS_LEFT_TO_RIGHT); #endif gtk_box_pack_start (GTK_BOX (vbox), topb, FALSE, FALSE, 2); } else if (g_ascii_strcasecmp (options.data.to_indicator, "bottom") == 0) { #if !GTK_CHECK_VERSION(3,0,0) gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (topb), GTK_PROGRESS_LEFT_TO_RIGHT); #endif gtk_box_pack_end (GTK_BOX (vbox), topb, FALSE, FALSE, 2); } else if (g_ascii_strcasecmp (options.data.to_indicator, "left") == 0) { #if !GTK_CHECK_VERSION(3,0,0) gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (topb), GTK_PROGRESS_BOTTOM_TO_TOP); #endif gtk_box_pack_start (GTK_BOX (hbox), topb, FALSE, FALSE, 2); } else if (g_ascii_strcasecmp (options.data.to_indicator, "right") == 0) { #if !GTK_CHECK_VERSION(3,0,0) gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (topb), GTK_PROGRESS_BOTTOM_TO_TOP); #endif gtk_box_pack_end (GTK_BOX (hbox), topb, FALSE, FALSE, 2); } if (settings.show_remain) { gchar *lbl = g_strdup_printf (_("%d sec"), options.data.timeout); #if GTK_CHECK_VERSION(3,0,0) gtk_progress_bar_set_show_text (GTK_PROGRESS_BAR (topb), TRUE); #endif gtk_progress_bar_set_text (GTK_PROGRESS_BAR (topb), lbl); g_free (lbl); } } /* must be after indicator! */ gtk_box_pack_end (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); if (options.data.image_on_top) { #if !GTK_CHECK_VERSION(3,0,0) hbox2 = gtk_hbox_new (FALSE, 0); #else hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); #endif gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0); } if (options.data.dialog_image) { GdkPixbuf *pb = NULL; pb = get_pixbuf (options.data.dialog_image, YAD_BIG_ICON); image = gtk_image_new_from_pixbuf (pb); if (pb) g_object_unref (pb); gtk_widget_set_name (image, "yad-dialog-image"); gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0); gtk_box_pack_start (GTK_BOX (hbox2), image, FALSE, FALSE, 2); } if (options.data.dialog_text) { /* for dnd's tooltip we don't need text label */ if (options.mode != YAD_MODE_DND || !options.dnd_data.tooltip) { gchar *buf = g_strcompress (options.data.dialog_text); text = gtk_label_new (NULL); if (!options.data.no_markup) gtk_label_set_markup (GTK_LABEL (text), buf); else gtk_label_set_text (GTK_LABEL (text), buf); g_free (buf); gtk_widget_set_name (text, "yad-dialog-label"); gtk_label_set_line_wrap (GTK_LABEL (text), TRUE); gtk_label_set_selectable (GTK_LABEL (text), options.data.selectable_labels); gtk_label_set_justify (GTK_LABEL (text), options.data.text_align); switch (options.data.text_align) { case GTK_JUSTIFY_LEFT: case GTK_JUSTIFY_FILL: gtk_misc_set_alignment (GTK_MISC (text), 0.0, 0.5); break; case GTK_JUSTIFY_CENTER: gtk_misc_set_alignment (GTK_MISC (text), 0.5, 0.5); break; case GTK_JUSTIFY_RIGHT: gtk_misc_set_alignment (GTK_MISC (text), 1.0, 0.5); break; } if (options.data.image_on_top) gtk_box_pack_start (GTK_BOX (hbox2), text, TRUE, TRUE, 2); else gtk_box_pack_start (GTK_BOX (vbox), text, FALSE, FALSE, 2); #if !GTK_CHECK_VERSION(3,0,0) if (!options.data.fixed) g_signal_connect (G_OBJECT (text), "size-allocate", G_CALLBACK (text_size_allocate_cb), NULL); #endif } } /* add main widget */ switch (options.mode) { case YAD_MODE_CALENDAR: main_widget = calendar_create_widget (dlg); break; case YAD_MODE_COLOR: main_widget = color_create_widget (dlg); break; case YAD_MODE_DND: dnd_init (dlg); break; case YAD_MODE_ENTRY: main_widget = entry_create_widget (dlg); break; case YAD_MODE_FILE: main_widget = file_create_widget (dlg); break; case YAD_MODE_FONT: main_widget = font_create_widget (dlg); break; case YAD_MODE_FORM: main_widget = form_create_widget (dlg); break; #ifdef HAVE_HTML case YAD_MODE_HTML: main_widget = html_create_widget (dlg); break; #endif case YAD_MODE_ICONS: main_widget = icons_create_widget (dlg); break; case YAD_MODE_LIST: main_widget = list_create_widget (dlg); break; case YAD_MODE_MULTI_PROGRESS: main_widget = multi_progress_create_widget (dlg); break; case YAD_MODE_NOTEBOOK: main_widget = notebook_create_widget (dlg); break; case YAD_MODE_PANED: main_widget = paned_create_widget (dlg); break; case YAD_MODE_PROGRESS: main_widget = progress_create_widget (dlg); break; case YAD_MODE_SCALE: main_widget = scale_create_widget (dlg); break; case YAD_MODE_TEXTINFO: main_widget = text_create_widget (dlg); break; default: ; } if (main_widget) { if (options.data.expander) { GtkWidget *exp; exp = gtk_expander_new_with_mnemonic (options.data.expander); gtk_expander_set_expanded (GTK_EXPANDER (exp), FALSE); gtk_container_add (GTK_CONTAINER (exp), main_widget); gtk_box_pack_start (GTK_BOX (vbox), exp, TRUE, TRUE, 2); } else gtk_box_pack_start (GTK_BOX (vbox), main_widget, TRUE, TRUE, 2); } /* add buttons */ if (!options.data.no_buttons) { if (options.data.buttons) { GSList *tmp = options.data.buttons; do { GtkWidget *btn; YadButton *b = (YadButton *) tmp->data; btn = gtk_button_new (); gtk_container_add (GTK_CONTAINER (btn), get_label (b->name, 2)); gtk_button_set_alignment (GTK_BUTTON (btn), 0.5, 0.5); g_object_set_data (G_OBJECT (btn), "resp", GINT_TO_POINTER (b->response)); g_signal_connect (G_OBJECT (btn), "clicked", G_CALLBACK (btn_cb), b->cmd); gtk_box_pack_start (GTK_BOX (bbox), btn, FALSE, FALSE, 0); tmp = tmp->next; } while (tmp != NULL); } else { if (options.mode == YAD_MODE_PROGRESS || options.mode == YAD_MODE_MULTI_PROGRESS) gtk_dialog_add_buttons (GTK_DIALOG (dlg), GTK_STOCK_CLOSE, YAD_RESPONSE_OK, NULL); else { if (gtk_alternative_dialog_button_order (NULL)) gtk_dialog_add_buttons (GTK_DIALOG (dlg), GTK_STOCK_OK, YAD_RESPONSE_OK, GTK_STOCK_CANCEL, YAD_RESPONSE_CANCEL, NULL); else gtk_dialog_add_buttons (GTK_DIALOG (dlg), GTK_STOCK_CANCEL, YAD_RESPONSE_CANCEL, GTK_STOCK_OK, YAD_RESPONSE_OK, NULL); } gtk_dialog_set_default_response (GTK_DIALOG (dlg), YAD_RESPONSE_OK); } gtk_button_box_set_layout (GTK_BUTTON_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), options.data.buttons_layout); } /* show widgets */ gtk_widget_show_all (gtk_dialog_get_content_area (GTK_DIALOG (dlg))); if (options.data.no_buttons) gtk_widget_hide (bbox); /* parse geometry, if given. must be after showing widget */ if (options.data.geometry && !options.data.maximized && !options.data.fullscreen) { gtk_widget_realize (dlg); gtk_window_parse_geometry (GTK_WINDOW (dlg), options.data.geometry); } gtk_widget_show (dlg); /* set maximized or fixed size after showing widget */ if (options.data.maximized) gtk_window_maximize (GTK_WINDOW (dlg)); else if (options.data.fullscreen) gtk_window_fullscreen (GTK_WINDOW (dlg)); else { gtk_window_set_resizable (GTK_WINDOW (dlg), !options.data.fixed); if (options.data.fixed) gtk_widget_set_size_request (dlg, options.data.width, options.data.height); } /* set timeout */ if (options.data.timeout) { g_timeout_add_seconds (options.data.timeout, timeout_cb, dlg); g_timeout_add_seconds (1, timeout_indicator_cb, topb); } #ifndef G_OS_WIN32 /* print xid */ if (options.print_xid) { fprintf (stderr, "0x%lX", GDK_WINDOW_XID (gtk_widget_get_window (dlg))); fflush (stderr); } #endif return dlg; }
/** * gimp_session_info_apply_geometry: * @info: * * Apply the geometry stored in the session info object to the * associated widget. **/ void gimp_session_info_apply_geometry (GimpSessionInfo *info) { GdkScreen *screen; GdkRectangle rect; gchar geom[32]; gint monitor; gboolean use_size; g_return_if_fail (GIMP_IS_SESSION_INFO (info)); g_return_if_fail (GTK_IS_WINDOW (info->p->widget)); screen = gtk_widget_get_screen (info->p->widget); use_size = (gimp_session_info_get_remember_size (info) && info->p->width > 0 && info->p->height > 0); if (use_size) { monitor = gimp_session_info_get_appropriate_monitor (screen, info->p->x, info->p->y, info->p->width, info->p->height); } else { monitor = gdk_screen_get_monitor_at_point (screen, info->p->x, info->p->y); } gdk_screen_get_monitor_geometry (screen, monitor, &rect); info->p->x = CLAMP (info->p->x, rect.x, rect.x + rect.width - (info->p->width > 0 ? info->p->width : 128)); info->p->y = CLAMP (info->p->y, rect.y, rect.y + rect.height - (info->p->height > 0 ? info->p->height : 128)); if (info->p->right_align && info->p->bottom_align) { g_strlcpy (geom, "-0-0", sizeof (geom)); } else if (info->p->right_align) { g_snprintf (geom, sizeof (geom), "-0%+d", info->p->y); } else if (info->p->bottom_align) { g_snprintf (geom, sizeof (geom), "%+d-0", info->p->x); } else { g_snprintf (geom, sizeof (geom), "%+d%+d", info->p->x, info->p->y); } gtk_window_parse_geometry (GTK_WINDOW (info->p->widget), geom); if (use_size) gtk_window_set_default_size (GTK_WINDOW (info->p->widget), info->p->width, info->p->height); /* Window managers and windowing systems suck. They have their own * ideas about WM standards and when it's appropriate to honor * user/application-set window positions and when not. Therefore, * use brute force and "manually" position dialogs whenever they * are shown. This is important especially for transient dialog, * because window managers behave even "smarter" then... */ if (GTK_IS_DIALOG (info->p->widget)) g_signal_connect (info->p->widget, "show", G_CALLBACK (gimp_session_info_dialog_show), info); }
int main(int argc, char **argv) { GdkScreen *screen; GdkColormap *colormap; GtkWidget *window, *widget,*hbox = NULL, *scrollbar, *scrolled_window = NULL; VteTerminal *terminal; char *env_add[] = { #ifdef VTE_DEBUG (char *) "FOO=BAR", (char *) "BOO=BIZ", #endif NULL}; const char *background = NULL; gboolean transparent = FALSE, audible = TRUE, blink = TRUE, debug = FALSE, dingus = FALSE, dbuffer = TRUE, console = FALSE, scroll = FALSE, keep = FALSE, icon_title = FALSE, shell = TRUE, highlight_set = FALSE, cursor_set = FALSE, reverse = FALSE, use_geometry_hints = TRUE, antialias = TRUE, use_scrolled_window = FALSE, show_object_notifications = FALSE; char *geometry = NULL; gint lines = 100; const char *message = "Launching interactive shell...\r\n"; const char *font = NULL; const char *termcap = NULL; const char *command = NULL; const char *working_directory = NULL; const char *output_file = NULL; char *pty_flags_string = NULL; char *cursor_shape_string = NULL; char *scrollbar_policy_string = NULL; GdkColor fore, back, tint, highlight, cursor; const GOptionEntry options[]={ { "antialias", 'A', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &antialias, "Disable the use of anti-aliasing", NULL }, { "background", 'B', 0, G_OPTION_ARG_FILENAME, &background, "Specify a background image", NULL }, { "console", 'C', 0, G_OPTION_ARG_NONE, &console, "Watch /dev/console", NULL }, { "dingus", 'D', 0, G_OPTION_ARG_NONE, &dingus, "Highlight URLs inside the terminal", NULL }, { "shell", 'S', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &shell, "Disable spawning a shell inside the terminal", NULL }, { "transparent", 'T', 0, G_OPTION_ARG_NONE, &transparent, "Enable the use of a transparent background", NULL }, { "double-buffer", '2', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &dbuffer, "Disable double-buffering", NULL }, { "audible", 'a', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &audible, "Use visible, instead of audible, terminal bell", NULL }, { "blink", 'b', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &blink, "Disable the blinking cursor", NULL }, { "command", 'c', 0, G_OPTION_ARG_STRING, &command, "Execute a command in the terminal", NULL }, { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug, "Enable various debugging checks", NULL }, { "font", 'f', 0, G_OPTION_ARG_STRING, &font, "Specify a font to use", NULL }, { "geometry", 'g', 0, G_OPTION_ARG_STRING, &geometry, "Set the size (in characters) and position", "GEOMETRY" }, { "highlight", 'h', 0, G_OPTION_ARG_NONE, &highlight_set, "Enable the cursor highlighting", NULL }, { "icon-title", 'i', 0, G_OPTION_ARG_NONE, &icon_title, "Enable the setting of the icon title", NULL }, { "keep", 'k', 0, G_OPTION_ARG_NONE, &keep, "Live on after the window closes", NULL }, { "scrollback-lines", 'n', 0, G_OPTION_ARG_INT, &lines, "Specify the number of scrollback-lines", NULL }, { "color-cursor", 'r', 0, G_OPTION_ARG_NONE, &cursor_set, "Enable a colored cursor", NULL }, { "cursor-shape", 0, 0, G_OPTION_ARG_STRING, &cursor_shape_string, "Set cursor shape (block|underline|ibeam)", NULL }, { "scroll-background", 's', 0, G_OPTION_ARG_NONE, &scroll, "Enable a scrolling background", NULL }, { "termcap", 't', 0, G_OPTION_ARG_STRING, &termcap, "Specify the terminal emulation to use", NULL }, { "working-directory", 'w', 0, G_OPTION_ARG_FILENAME, &working_directory, "Specify the initial working directory of the terminal", NULL }, { "reverse", 0, 0, G_OPTION_ARG_NONE, &reverse, "Reverse foreground/background colors", NULL }, { "no-geometry-hints", 'G', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &use_geometry_hints, "Allow the terminal to be resized to any dimension, not constrained to fit to an integer multiple of characters", NULL }, { "scrolled-window", 'W', 0, G_OPTION_ARG_NONE, &use_scrolled_window, "Use a GtkScrolledWindow as terminal container", NULL }, { "scrollbar-policy", 'P', 0, G_OPTION_ARG_STRING, &scrollbar_policy_string, "Set the policy for the vertical scroolbar in the scrolled window (always|auto|never; default:always)", NULL }, { "object-notifications", 'N', 0, G_OPTION_ARG_NONE, &show_object_notifications, "Print VteTerminal object notifications", NULL }, { "output-file", 0, 0, G_OPTION_ARG_STRING, &output_file, "Save terminal contents to file at exit", NULL }, { "pty-flags", 0, 0, G_OPTION_ARG_STRING, &pty_flags_string, "PTY flags set from default|no-utmp|no-wtmp|no-lastlog|no-helper|no-fallback", NULL }, { NULL } }; GOptionContext *context; GError *error = NULL; VteTerminalCursorShape cursor_shape = VTE_CURSOR_SHAPE_BLOCK; GtkPolicyType scrollbar_policy = GTK_POLICY_ALWAYS; VtePtyFlags pty_flags = VTE_PTY_DEFAULT; /* Have to do this early. */ if (getenv("VTE_PROFILE_MEMORY")) { if (atol(getenv("VTE_PROFILE_MEMORY")) != 0) { g_mem_set_vtable(glib_mem_profiler_table); } } context = g_option_context_new (" - test VTE terminal emulation"); g_option_context_add_main_entries (context, options, NULL); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); if (error != NULL) { g_printerr ("Failed to parse command line arguments: %s\n", error->message); g_error_free (error); return 1; } if (cursor_shape_string) { cursor_shape = parse_enum(VTE_TYPE_TERMINAL_CURSOR_SHAPE, cursor_shape_string); g_free(cursor_shape_string); } if (scrollbar_policy_string) { scrollbar_policy = parse_enum(GTK_TYPE_POLICY_TYPE, scrollbar_policy_string); g_free(scrollbar_policy_string); } if (pty_flags_string) { pty_flags |= parse_flags(VTE_TYPE_PTY_FLAGS, pty_flags_string); g_free(pty_flags_string); } if (!reverse) { back.red = back.green = back.blue = 0xffff; fore.red = fore.green = fore.blue = 0x0000; } else { back.red = back.green = back.blue = 0x0000; fore.red = fore.green = fore.blue = 0xffff; } highlight.red = highlight.green = highlight.blue = 0xc000; cursor.red = 0xffff; cursor.green = cursor.blue = 0x8000; tint.red = tint.green = tint.blue = 0; tint = back; gdk_window_set_debug_updates(debug); /* Create a window to hold the scrolling shell, and hook its * delete event to the quit function.. */ window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_container_set_resize_mode(GTK_CONTAINER(window), GTK_RESIZE_IMMEDIATE); /* Set ARGB colormap */ screen = gtk_widget_get_screen (window); colormap = gdk_screen_get_rgba_colormap (screen); if (colormap) gtk_widget_set_colormap(window, colormap); if (use_scrolled_window) { scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_NEVER, scrollbar_policy); gtk_container_add(GTK_CONTAINER(window), scrolled_window); } else { /* Create a box to hold everything. */ hbox = gtk_hbox_new(0, FALSE); gtk_container_add(GTK_CONTAINER(window), hbox); } /* Create the terminal widget and add it to the scrolling shell. */ widget = vte_terminal_new(); terminal = VTE_TERMINAL (widget); if (!dbuffer) { gtk_widget_set_double_buffered(widget, dbuffer); } g_signal_connect(terminal, "child-exited", G_CALLBACK(child_exit_cb), NULL); if (show_object_notifications) g_signal_connect(terminal, "notify", G_CALLBACK(terminal_notify_cb), NULL); if (use_scrolled_window) { gtk_container_add(GTK_CONTAINER(scrolled_window), GTK_WIDGET(terminal)); } else { gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, 0); } /* Connect to the "char_size_changed" signal to set geometry hints * whenever the font used by the terminal is changed. */ if (use_geometry_hints) { char_size_changed(widget, 0, 0, window); g_signal_connect(widget, "char-size-changed", G_CALLBACK(char_size_changed), window); g_signal_connect(widget, "realize", G_CALLBACK(char_size_realized), window); } /* Connect to the "window_title_changed" signal to set the main * window's title. */ g_signal_connect(widget, "window-title-changed", G_CALLBACK(window_title_changed), window); if (icon_title) { g_signal_connect(widget, "icon-title-changed", G_CALLBACK(icon_title_changed), window); } /* Connect to the "status-line-changed" signal. */ g_signal_connect(widget, "status-line-changed", G_CALLBACK(status_line_changed), widget); /* Connect to the "button-press" event. */ g_signal_connect(widget, "button-press-event", G_CALLBACK(button_pressed), widget); /* Connect to application request signals. */ g_signal_connect(widget, "iconify-window", G_CALLBACK(iconify_window), window); g_signal_connect(widget, "deiconify-window", G_CALLBACK(deiconify_window), window); g_signal_connect(widget, "raise-window", G_CALLBACK(raise_window), window); g_signal_connect(widget, "lower-window", G_CALLBACK(lower_window), window); g_signal_connect(widget, "maximize-window", G_CALLBACK(maximize_window), window); g_signal_connect(widget, "restore-window", G_CALLBACK(restore_window), window); g_signal_connect(widget, "refresh-window", G_CALLBACK(refresh_window), window); g_signal_connect(widget, "resize-window", G_CALLBACK(resize_window), window); g_signal_connect(widget, "move-window", G_CALLBACK(move_window), window); /* Connect to font tweakage. */ g_signal_connect(widget, "increase-font-size", G_CALLBACK(increase_font_size), window); g_signal_connect(widget, "decrease-font-size", G_CALLBACK(decrease_font_size), window); if (!use_scrolled_window) { /* Create the scrollbar for the widget. */ scrollbar = gtk_vscrollbar_new(terminal->adjustment); gtk_box_pack_start(GTK_BOX(hbox), scrollbar, FALSE, FALSE, 0); } /* Set some defaults. */ vte_terminal_set_audible_bell(terminal, audible); vte_terminal_set_visible_bell(terminal, !audible); vte_terminal_set_cursor_blink_mode(terminal, blink ? VTE_CURSOR_BLINK_SYSTEM : VTE_CURSOR_BLINK_OFF); vte_terminal_set_scroll_background(terminal, scroll); vte_terminal_set_scroll_on_output(terminal, FALSE); vte_terminal_set_scroll_on_keystroke(terminal, TRUE); vte_terminal_set_scrollback_lines(terminal, lines); vte_terminal_set_mouse_autohide(terminal, TRUE); if (background != NULL) { vte_terminal_set_background_image_file(terminal, background); } if (transparent) { vte_terminal_set_background_transparent(terminal, TRUE); } vte_terminal_set_background_tint_color(terminal, &tint); vte_terminal_set_colors(terminal, &fore, &back, NULL, 0); vte_terminal_set_opacity(terminal, 0xdddd); if (highlight_set) { vte_terminal_set_color_highlight(terminal, &highlight); } if (cursor_set) { vte_terminal_set_color_cursor(terminal, &cursor); } if (termcap != NULL) { vte_terminal_set_emulation(terminal, termcap); } vte_terminal_set_cursor_shape(terminal, cursor_shape); /* Set the default font. */ vte_terminal_set_font_from_string_full(terminal, font, antialias ? VTE_ANTI_ALIAS_USE_DEFAULT : VTE_ANTI_ALIAS_FORCE_DISABLE); /* Match "abcdefg". */ if (dingus) { int id; GRegex *regex; regex = g_regex_new (DINGUS1, 0, 0, NULL); id = vte_terminal_match_add_gregex(terminal, regex, 0); g_regex_unref (regex); vte_terminal_match_set_cursor_type(terminal, id, GDK_GUMBY); regex = g_regex_new (DINGUS2, 0, 0, NULL); id = vte_terminal_match_add_gregex(terminal, regex, 0); g_regex_unref (regex); vte_terminal_match_set_cursor_type(terminal, id, GDK_HAND1); } if (console) { /* Open a "console" connection. */ int consolefd = -1, yes = 1, watch; GIOChannel *channel; consolefd = open("/dev/console", O_RDONLY | O_NOCTTY); if (consolefd != -1) { /* Assume failure. */ console = FALSE; #ifdef TIOCCONS if (ioctl(consolefd, TIOCCONS, &yes) != -1) { /* Set up a listener. */ channel = g_io_channel_unix_new(consolefd); watch = g_io_add_watch(channel, G_IO_IN, read_and_feed, widget); g_signal_connect(widget, "eof", G_CALLBACK(disconnect_watch), GINT_TO_POINTER(watch)); g_signal_connect(widget, "child-exited", G_CALLBACK(disconnect_watch), GINT_TO_POINTER(watch)); g_signal_connect(widget, "realize", G_CALLBACK(take_xconsole_ownership), NULL); #ifdef VTE_DEBUG vte_terminal_feed(terminal, "Console log for ...\r\n", -1); #endif /* Record success. */ console = TRUE; } #endif } else { /* Bail back to normal mode. */ g_warning(_("Could not open console.\n")); close(consolefd); console = FALSE; } } if (!console) { if (shell) { GError *err = NULL; char **command_argv = NULL; int command_argc; GPid pid = -1; _VTE_DEBUG_IF(VTE_DEBUG_MISC) vte_terminal_feed(terminal, message, -1); if (command == NULL) command = "/bin/sh"; // FIXMEchpe if (command != NULL) { if (!g_shell_parse_argv(command, &command_argc, &command_argv, &err) || !vte_terminal_fork_command_full(terminal, pty_flags, NULL, command_argv, env_add, G_SPAWN_SEARCH_PATH, NULL, NULL, &pid, &err)) { g_warning("Failed to fork: %s\n", err->message); g_error_free(err); } else { g_print("Fork succeeded, PID %d\n", pid); } } g_strfreev(command_argv); #ifdef VTE_DEBUG if (command == NULL) { vte_terminal_feed_child(terminal, "pwd\n", -1); } #endif } else { long i; i = vte_terminal_forkpty(terminal, env_add, working_directory, TRUE, TRUE, TRUE); switch (i) { case -1: /* abnormal */ g_warning("Error in vte_terminal_forkpty(): %s", strerror(errno)); break; case 0: /* child */ for (i = 0; ; i++) { switch (i % 3) { case 0: case 1: g_print("%ld\n", i); break; case 2: g_printerr("%ld\n", i); break; } sleep(1); } _exit(0); break; default: g_print("Child PID is %ld (mine is %ld).\n", (long) i, (long) getpid()); /* normal */ break; } } } g_object_set_data (G_OBJECT (widget), "output_file", (gpointer) output_file); /* Go for it! */ g_signal_connect(widget, "child-exited", G_CALLBACK(child_exited), window); g_signal_connect(window, "delete-event", G_CALLBACK(delete_event), widget); add_weak_pointer(G_OBJECT(widget), &widget); add_weak_pointer(G_OBJECT(window), &window); gtk_widget_realize(widget); if (geometry) { if (!gtk_window_parse_geometry (GTK_WINDOW(window), geometry)) { g_warning (_("Could not parse the geometry spec passed to --geometry")); } } gtk_widget_show_all(window); gtk_main(); g_assert(widget == NULL); g_assert(window == NULL); if (keep) { while (TRUE) { sleep(60); } } return 0; }
static void create_window (GdkWindowHints mask) { GtkWidget *window; GtkWidget *drawing_area; GtkWidget *grid; GtkWidget *label; GtkWidget *button; GdkGeometry geometry; GString *label_text = g_string_new (NULL); int border = 0; if ((mask & GDK_HINT_RESIZE_INC) != 0) g_string_append (label_text, "Gridded\n"); if ((mask & GDK_HINT_BASE_SIZE) != 0) g_string_append (label_text, "Base\n"); if ((mask & GDK_HINT_MIN_SIZE) != 0) { g_string_append (label_text, "Minimum\n"); if ((mask & GDK_HINT_BASE_SIZE) == 0) g_string_append (label_text, "(base=min)\n"); } if ((mask & GDK_HINT_MAX_SIZE) != 0) g_string_append (label_text, "Maximum\n"); if (label_text->len > 0) g_string_erase (label_text, label_text->len - 1, 1); else g_string_append (label_text, "No Options"); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (window, "destroy", G_CALLBACK (on_window_destroy), NULL); grid = gtk_grid_new (); gtk_container_set_border_width (GTK_CONTAINER (grid), 10); label = gtk_label_new (label_text->str); gtk_widget_set_hexpand (label, TRUE); gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1); label = gtk_label_new ("A\nB\nC\nD\nE"); gtk_grid_attach (GTK_GRID (grid), label, 1, 1, 1, 1); drawing_area = gtk_drawing_area_new (); g_signal_connect (drawing_area, "draw", G_CALLBACK (on_drawing_area_draw), GUINT_TO_POINTER (mask)); gtk_widget_set_hexpand (drawing_area, TRUE); gtk_widget_set_vexpand (drawing_area, TRUE); gtk_grid_attach (GTK_GRID (grid), drawing_area, 0, 1, 1, 1); button = gtk_button_new_with_label ("Resize"); g_signal_connect (button, "clicked", G_CALLBACK (on_resize_clicked), GUINT_TO_POINTER (mask)); gtk_widget_set_hexpand (button, TRUE); gtk_grid_attach (GTK_GRID (grid), button, 0, 2, 1, 1); gtk_container_add (GTK_CONTAINER (window), grid); if ((mask & GDK_HINT_BASE_SIZE) != 0) { border = BORDER; geometry.base_width = border * 2; geometry.base_height = border * 2; } if ((mask & GDK_HINT_RESIZE_INC) != 0) { geometry.width_inc = GRID_SIZE; geometry.height_inc = GRID_SIZE; } if ((mask & GDK_HINT_MIN_SIZE) != 0) { geometry.min_width = 5 * GRID_SIZE + 2 * border; geometry.min_height = 5 * GRID_SIZE + 2 * border; } if ((mask & GDK_HINT_MAX_SIZE) != 0) { geometry.max_width = 15 * GRID_SIZE + 2 * border; geometry.max_height = 15 * GRID_SIZE + 2 * border; } /* Contents must be set up before gtk_window_parse_geometry() */ gtk_widget_show_all (grid); gtk_window_set_geometry_hints (GTK_WINDOW (window), drawing_area, &geometry, mask); if ((mask & GDK_HINT_RESIZE_INC) != 0) { if (geometry_string) gtk_window_parse_geometry (GTK_WINDOW (window), geometry_string); else gtk_window_set_default_geometry (GTK_WINDOW (window), 10, 10); } else { gtk_window_set_default_geometry (GTK_WINDOW (window), 10 * GRID_SIZE, 10 * GRID_SIZE); } gtk_widget_show (window); window_count++; }
int main (int argc, char *argv[]) { ScreenSaver *screen_saver; GtkWidget *window; GtkWidget *drawing_area; #if GTK_CHECK_VERSION (3, 0, 0) GdkRGBA bg; GdkRGBA fg; #else GtkStyle *style; GtkStateType state; #endif GError *error; error = NULL; bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); gtk_init_with_args (&argc, &argv, /* translators: the word "image" here * represents a command line argument */ _("image - floats images around the screen"), options, GETTEXT_PACKAGE, &error); if (error != NULL) { g_printerr (_("%s. See --help for usage information.\n"), _(error->message)); g_error_free (error); return EX_SOFTWARE; } if ((filenames == NULL) || (filenames[0] == NULL) || (filenames[1] != NULL)) { g_printerr (_("You must specify one image. See --help for usage " "information.\n")); return EX_USAGE; } window = gs_theme_window_new (); g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (gtk_main_quit), NULL); drawing_area = gtk_drawing_area_new (); #if GTK_CHECK_VERSION (3, 0, 0) bg.red = 0; bg.green = 0; bg.blue = 0; bg.alpha = 1.0; fg.red = 0.8; fg.green = 0.8; fg.blue = 0.8; fg.alpha = 1.0; gtk_widget_override_background_color (drawing_area, 0, &bg); gtk_widget_override_color (drawing_area, 0, &fg); #else style = drawing_area->style; state = (GtkStateType) 0; while (state < (GtkStateType) G_N_ELEMENTS (style->bg)) { gtk_widget_modify_bg (drawing_area, state, &style->mid[state]); state++; } #endif gtk_widget_show (drawing_area); gtk_container_add (GTK_CONTAINER (window), drawing_area); screen_saver = screen_saver_new (GTK_DRAWING_AREA (drawing_area), filenames[0], max_floater_count, should_do_rotations, should_show_paths); g_strfreev (filenames); if (should_print_stats) g_timeout_add (STAT_PRINT_FREQUENCY, (GSourceFunc) do_print_screen_saver_stats, screen_saver); if ((geometry == NULL) || !gtk_window_parse_geometry (GTK_WINDOW (window), geometry)) gtk_window_set_default_size (GTK_WINDOW (window), 640, 480); gtk_widget_show (window); gtk_main (); screen_saver_free (screen_saver); return EX_OK; }