示例#1
0
static VALUE
term_set_font(int argc, VALUE *argv, VALUE self)
{
    VALUE font_desc_or_name, rb_antialias;
    VteTerminalAntiAlias antialias = VTE_ANTI_ALIAS_USE_DEFAULT;
    VteTerminal *term;

    rb_scan_args(argc, argv, "11", &font_desc_or_name, &rb_antialias);

    term = RVAL2TERM(self);
    if (!NIL_P(rb_antialias))
        antialias = RVAL2AA(rb_antialias);

    if (rb_obj_is_kind_of(font_desc_or_name, rb_cString)) {
        char *name;
        name = RVAL2CSTR(font_desc_or_name);
        if (NIL_P(rb_antialias))
            vte_terminal_set_font_from_string(term, name);
        else
            vte_terminal_set_font_from_string_full(term, name, antialias);
    } else {
        PangoFontDescription *font_desc;
        font_desc = RVAL2PFD(font_desc_or_name);
        if (NIL_P(rb_antialias))
            vte_terminal_set_font(term, font_desc);
        else
            vte_terminal_set_font_full(term, font_desc, antialias);
    }

    return Qnil;
}
示例#2
0
void fake_vte_terminal_set_font_from_string(GtkWidget *vte, const char *font_name, gboolean anti_alias)
{
#ifdef DETAIL
	g_debug("! Launch fake_vte_terminal_set_font_from_string() with vte = %p, font_name = %s, anti_alias = %d", vte, font_name, anti_alias);
#endif
#ifdef SAFEMODE
	if ((vte==NULL) || (font_name==NULL)) return;
#endif

#ifdef USE_VTE_TERMINAL_SET_FONT
	PangoFontDescription *font_desc = pango_font_description_from_string(font_name);
	vte_terminal_set_font(VTE_TERMINAL(vte), font_desc);
#else
	vte_terminal_set_font_from_string_full( VTE_TERMINAL(vte), font_name, anti_alias);
#endif
}
示例#3
0
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;
}
示例#4
0
文件: font.c 项目: enferex/LilyTerm
void apply_font_to_every_vte(GtkWidget *window, gchar *new_font_name, glong column, glong row)
{
#ifdef DETAIL
	g_debug("! Launch apply_font_to_every_vte() with window = %p, new_font_name = %s,"
		" column = %ld, row = %ld", window, new_font_name, column, row);
#endif
#ifdef SAFEMODE
	if ((window==NULL) || (new_font_name==NULL) || (column<1) || (row<1)) return;
#endif
	struct Window *win_data = (struct Window *)g_object_get_data(G_OBJECT(window), "Win_Data");
	// g_debug("Get win_data = %d when apply font to every vte!", win_data);
#ifdef SAFEMODE
	if (win_data==NULL) return;
#endif

	struct Page *page_data = NULL;
	gint i;

	// g_debug("Trying to apply every vte to %dx%d!", column, row);
	// g_debug("Trying to apply font %s to every vte!", new_font_name);

	for (i=0; i<gtk_notebook_get_n_pages(GTK_NOTEBOOK(win_data->notebook)); i++)
	{
		page_data = get_page_data_from_nth_page(win_data, i);
#ifdef SAFEMODE
		if (page_data==NULL) continue;
#endif
#ifdef USE_GTK3_GEOMETRY_METHOD
		save_current_vte_geometry(win_data, page_data->vte);
#endif
		// g_debug("The default font for %d page is: %s (%s)", i, page_data->font_name, new_font_name);
		vte_terminal_set_font_from_string_full(VTE_TERMINAL(page_data->vte),
						       new_font_name,
						       win_data->font_anti_alias);
		vte_terminal_set_size(VTE_TERMINAL(page_data->vte), column, row);
#ifdef USE_GTK3_GEOMETRY_METHOD
		page_data->column = column;
		page_data->row = row;
#  ifdef GEOMETRY
		g_debug("@ apply_font_to_every_vte (for %p): Trying set the geometry to %ld x %ld",
			window, column, row);
#  endif
#endif
		g_free(page_data->font_name);
		page_data->font_name = g_strdup(new_font_name);

		// g_debug("The new font for %d page is: %s (%s)", i, page_data->font_name, new_font_name);
	}

	// g_debug("Set hints to FALSE!");
	win_data->update_hints = 1;
	// win_data->keep_vte_size |= 0x30;
	// g_debug("window_resizable in apply_font_to_every_vte!");
	// window_resizable(window, page_data->vte, 2, 1);
	// g_debug("apply_font_to_every_vte(): launch keep_window_size()!");
#ifdef USE_GTK2_GEOMETRY_METHOD
#  ifdef GEOMETRY
	g_debug("@ apply_font_to_every_vte(): Call keep_gtk2_window_size() with win_data->unfullscreen = %d",
		win_data->unfullscreen);
#  endif
	// Don't need to call keep_gtk2_window_size() when fullscreen
	switch (win_data->unfullscreen)
	{
		case FULLSCREEN_NORMAL:
		case FULLSCREEN_UNFS_OK:
#  ifdef GEOMETRY
			g_debug("@ apply_font_to_every_vte(): Call keep_gtk2_window_size() with keep_vte_size = %x",
				win_data->keep_vte_size);
#  endif
			keep_gtk2_window_size (win_data, page_data->vte, 0x380);
			break;
		default:
			break;
	}
#endif
#ifdef USE_GTK3_GEOMETRY_METHOD
	win_data->keep_vte_size += 2;
#  ifdef GEOMETRY
	g_debug("@ apply_font_to_every_vte(for %p): Set win_data->keep_vte_size to %d",
		win_data->window, win_data->keep_vte_size);
#  endif
#endif
}
示例#5
0
文件: font.c 项目: enferex/LilyTerm
void reset_vte_size(GtkWidget *vte, gchar *new_font_name, Font_Reset_Type type)
{
#ifdef DETAIL
	g_debug("! Launch reset_vte_size() with vte = %p, new_font_name = %s, type = %d",
		vte, new_font_name, type);
#endif
#ifdef SAFEMODE
	if ((vte==NULL) || (new_font_name==NULL)) return;
#endif

	// type 0, RESET_CURRENT_TAB_FONT: change current page's font
	// type 1, RESET_ALL_TO_CURRENT_TAB: apply current column & row to every vte
	// type 2, RESET_ALL_TO_DEFAULT: apply default column & row to every vte
	// type 3, RESET_ALL_TO_SYSTEM: apply system column & row to every vte

	struct Page *page_data = (struct Page *)g_object_get_data(G_OBJECT(vte), "Page_Data");
#ifdef SAFEMODE
	if (page_data==NULL) return;
#endif
	struct Window *win_data = (struct Window *)g_object_get_data(G_OBJECT(page_data->window), "Win_Data");
#ifdef SAFEMODE
	if (win_data==NULL) return;
#endif
	// g_debug("Get win_data = %d when reset vte size!", win_data);

	switch (type)
	{
		case RESET_CURRENT_TAB_FONT:
			// We need to apply a new font to a single vte.
			// so that we should insure that this won't change the size of window.
			// g_debug("Trying to apply font %s to vte", current_font_name);
			vte_terminal_set_font_from_string_full( VTE_TERMINAL(vte),
								new_font_name,
								win_data->font_anti_alias);
			// g_debug("reset_vte_size(): call window_resizable() with run_once = %d", win_data->update_hints);
			// g_debug("reset_vte_size(): launch update_window_hint()!");
			update_window_hint(win_data, page_data);
			break;
		case RESET_ALL_TO_CURRENT_TAB:
			// increase/decrease window size & font size for every vte
			// g_debug("Trying to apply font %s to every vte", current_font_name);
			// struct Page *page_data = (struct Page *)g_object_get_data(G_OBJECT(current_vte), "Page_Data");
			apply_font_to_every_vte( page_data->window, new_font_name,
						 vte_terminal_get_column_count(VTE_TERMINAL(win_data->current_vte)),
						 vte_terminal_get_row_count(VTE_TERMINAL(win_data->current_vte)));
			break;
		case RESET_ALL_TO_DEFAULT:
			// reset window size & font size for every vte
			// g_debug("Trying to apply font %s to every vte", current_font_name);
			apply_font_to_every_vte(page_data->window, new_font_name,
						win_data->default_column, win_data->default_row);
			break;
		case RESET_ALL_TO_SYSTEM:
			// reset window size & font size for every vte
			// g_debug("Trying to apply font %s to every vte", current_font_name);
			apply_font_to_every_vte(page_data->window, new_font_name,
						SYSTEM_COLUMN, SYSTEM_ROW);
			break;
		default:
#ifdef FATAL
			print_switch_out_of_range_error_dialog("reset_vte_size", "type", type);
#endif
			break;
	}
}
示例#6
0
void apply_new_win_data_to_page (struct Window *win_data_orig,
				 struct Window *win_data,
				 struct Page *page_data)
{
#ifdef DETAIL
	g_debug("! Launch apply_new_win_data_to_page() with win_data_orig = %p, win_data = %p, page_data = %p",
		win_data_orig, win_data, page_data);
#endif
#ifdef SAFEMODE
	if ((win_data_orig==NULL) || (win_data==NULL) || (page_data==NULL) || (page_data->vte==NULL)) return;
#endif
	// if (win_data_orig->use_rgba != win_data->use_rgba)
	//	init_rgba(win_data);
#ifdef ENABLE_RGBA
    	set_window_opacity (NULL, 0, win_data->window_opacity, win_data);
#endif

	init_monitor_cmdline_datas(win_data, page_data);

	if (win_data_orig->enable_hyperlink != win_data->enable_hyperlink)
		set_hyprelink(win_data, page_data);

// ---- the color used in vte ---- //
	gboolean update_color = FALSE;

	if (compare_color(&(win_data_orig->cursor_color), &(win_data->cursor_color)) ||
	    (win_data_orig->have_custom_color != win_data->have_custom_color) ||
	    (win_data_orig->use_custom_theme != win_data->use_custom_theme) ||
	    (win_data_orig->color_brightness != win_data->color_brightness))
	    	update_color = TRUE;

	gint i;
	if (! update_color && (win_data->use_custom_theme))
	{
		for (i=0; i<COLOR; i++)
			if (compare_color(&(win_data_orig->color[i]), &(win_data->color[i])))
				update_color = TRUE;
	}
	if (update_color)
		set_vte_color(page_data->vte, use_default_vte_theme(win_data), win_data->cursor_color, win_data->color, FALSE);

// ---- tabs on notebook ---- //

	if (win_data_orig->tabs_bar_position != win_data->tabs_bar_position)
	{
		if (win_data->tabs_bar_position)
			gtk_notebook_set_tab_pos(GTK_NOTEBOOK(win_data->notebook), GTK_POS_BOTTOM);
		else
			gtk_notebook_set_tab_pos(GTK_NOTEBOOK(win_data->notebook), GTK_POS_TOP);
	}

	// the fill_tabs_bar may not always work, so we should call set_fill_tabs_bar() every time.
	// if (win_data_orig->fill_tabs_bar != win_data->fill_tabs_bar)
		set_fill_tabs_bar(GTK_NOTEBOOK(win_data->notebook), win_data->fill_tabs_bar, page_data);

	if (win_data_orig->page_width != win_data->page_width)
		set_page_width(win_data, page_data);

	// g_debug("ORI: %d", win_data_orig->page_shows_current_cmdline ||
	//		   win_data_orig->page_shows_current_dir ||
	//		   win_data_orig->page_shows_window_title);
	// g_debug("NEW: %d", win_data->page_shows_current_cmdline ||
	//		   win_data->page_shows_current_dir ||
	//		   win_data->page_shows_window_title);
	if ((proc_exist) &&
	    ((page_data->page_update_method != PAGE_METHOD_NORMAL) ||
	    (win_data->page_shows_current_cmdline ||
	     win_data->page_shows_current_dir ||
	     win_data->page_shows_window_title)))
	{
		// FIXME: Is it necessary?
		if (page_data->page_update_method == PAGE_METHOD_WINDOW_TITLE) page_data->window_title_updated = 1;
		page_data->page_update_method = PAGE_METHOD_REFRESH;
	}
	// g_debug("page_data->page_update_method = %d", page_data->page_update_method);

	if (win_data->page_shows_window_title != win_data_orig->page_shows_window_title)
		add_remove_window_title_changed_signal(page_data);

	if (win_data->check_root_privileges != win_data_orig->check_root_privileges)
	{
		if (win_data->check_root_privileges)
			page_data->is_root = check_is_root(page_data->displayed_tpgid);
		else
			page_data->is_root = FALSE;
		// g_debug("apply_new_win_data_to_page(): page_data->is_root = %d", page_data->is_root);
	}

	if (page_data->is_bold)
	{
		if (page_data->vte == win_data->current_vte)
		{
			if (win_data->bold_current_page_name == FALSE)
			{
				page_data->is_bold = page_data->should_be_bold;
				if (win_data->bold_action_page_name == FALSE)
					page_data->is_bold = FALSE;
			}
		}
		else
		{
			if (win_data->bold_action_page_name == FALSE)
				page_data->is_bold = FALSE;
		}
	}
	else
	{
		if (page_data->vte == win_data->current_vte)
			page_data->is_bold = win_data->bold_current_page_name;
		else if (win_data->bold_action_page_name == TRUE)
			page_data->is_bold = page_data->should_be_bold;
	}

	if ((win_data_orig->window_title_shows_current_page != win_data->window_title_shows_current_page) ||
	    (win_data_orig->window_title_append_package_name != win_data->window_title_append_package_name))
	{
		check_and_update_window_title(win_data, page_data->custom_window_title,
					      page_data->page_no+1, page_data->custom_page_name,
					      page_data->page_name);
		// g_debug("FINAL: New window title = %s", gtk_window_get_title(GTK_WINDOW(win_data->window)));
	}

	get_and_update_page_name(page_data, FALSE);

	if ((win_data_orig->show_close_button_on_tab != win_data->show_close_button_on_tab) ||
	    (win_data_orig->show_close_button_on_all_tabs != win_data->show_close_button_on_all_tabs))
		show_close_button_on_tab(win_data, page_data);

// ---- font ---- //
	if (win_data_orig->font_anti_alias != win_data->font_anti_alias)
		vte_terminal_set_font_from_string_full (VTE_TERMINAL(page_data->vte),
							page_data->font_name,
							win_data->font_anti_alias);

// ---- other settings for init a vte ---- //

	if (compare_strings(win_data_orig->word_chars, win_data->word_chars, TRUE))
		vte_terminal_set_word_chars(VTE_TERMINAL(page_data->vte), win_data->word_chars);

	if (win_data_orig->show_scroll_bar != win_data->show_scroll_bar)
		// hide_scroll_bar(win_data, page_data);
		show_and_hide_scroll_bar(page_data, check_show_or_hide_scroll_bar(win_data));

	if (win_data_orig->scroll_bar_position != win_data->scroll_bar_position)
	{
		g_object_ref(page_data->vte);
		gtk_container_remove (GTK_CONTAINER(page_data->hbox), page_data->vte);
		g_object_ref(page_data->scroll_bar);
		gtk_container_remove (GTK_CONTAINER(page_data->hbox), page_data->scroll_bar);

		pack_vte_and_scroll_bar_to_hbox(win_data, page_data);

		g_object_unref(page_data->vte);
		g_object_unref(page_data->scroll_bar);
	}

	if (compare_color(&(win_data_orig->color[0]), &(win_data->color[0])) ||
	    (win_data_orig->transparent_background != win_data->transparent_background) ||
	    (win_data_orig->background_saturation != win_data->background_saturation) ||
	    (win_data_orig->scroll_background != win_data->scroll_background) ||
	    compare_strings (win_data_orig->background_image, win_data->background_image, TRUE))
		set_background_saturation (NULL, 0, win_data->background_saturation, page_data->vte);

	if (win_data_orig->scrollback_lines != win_data->scrollback_lines)
		vte_terminal_set_scrollback_lines (VTE_TERMINAL(page_data->vte), win_data->scrollback_lines);

	if (win_data_orig->cursor_blinks != win_data->cursor_blinks)
		set_cursor_blink(win_data, page_data);

	if (win_data_orig->allow_bold_text != win_data->allow_bold_text)
		vte_terminal_set_allow_bold(VTE_TERMINAL(page_data->vte), win_data->allow_bold_text);

	if (win_data_orig->audible_bell != win_data->audible_bell)
		vte_terminal_set_audible_bell (VTE_TERMINAL(page_data->vte), win_data->audible_bell);

	if (win_data_orig->visible_bell != win_data->visible_bell)
		vte_terminal_set_visible_bell (VTE_TERMINAL(page_data->vte), win_data->visible_bell);
#ifdef ENABLE_BEEP_SINGAL
	if (win_data_orig->urgent_bell != win_data->urgent_bell)
		set_vte_urgent_bell(win_data, page_data);
#endif
	if (win_data_orig->erase_binding != win_data->erase_binding)
		vte_terminal_set_backspace_binding (VTE_TERMINAL(page_data->vte), win_data->erase_binding);
#ifdef ENABLE_CURSOR_SHAPE
	if (win_data_orig->cursor_shape != win_data->cursor_shape)
		vte_terminal_set_cursor_shape(VTE_TERMINAL(page_data->vte), win_data->cursor_shape);
#endif
	if (compare_strings(win_data_orig->emulate_term, win_data->emulate_term, TRUE))
		vte_terminal_set_emulation (VTE_TERMINAL(page_data->vte), win_data->emulate_term);
}
示例#7
0
// to init a new page
void init_new_page(struct Window *win_data,
		   struct Page *page_data,
		   glong column,
		   glong row)
{
#ifdef DETAIL
	g_debug("! Launch init_new_page() with win_data = %p, page_data = %p, "
		" column = %ld, row = %ld", win_data, page_data, column, row);
#endif
#ifdef SAFEMODE
	if ((win_data==NULL) || (page_data==NULL) || (page_data->vte==NULL)) return;
#endif
	// g_debug("Get win_data = %d when initing new page!", win_data);

#ifdef SAFEMODE
	if (page_data->font_name)
	{
#endif
		// set font
		// g_debug("Set Font AA = %d", win_data->font_anti_alias);
		vte_terminal_set_font_from_string_full (VTE_TERMINAL(page_data->vte),
							page_data->font_name,
							win_data->font_anti_alias);
#ifdef SAFEMODE
	}
#endif
	//g_debug("Got font size from %s: %d", font_name, pango_font_description_get_size (
	//	  pango_font_description_from_string(font_name))/PANGO_SCALE);

	// set terminal size
	// g_debug("Set the vte size to: %dx%d", column, row);
#ifdef SAFEMODE
	if (page_data->vte)
#endif
		vte_terminal_set_size(VTE_TERMINAL(page_data->vte), column, row);

#ifdef GEOMETRY
#  ifdef USE_GTK2_GEOMETRY_METHOD
	g_debug("@ init_new_page(for %p, vte = %p): Set win_data->keep_vte_size to %d, and column = %ld, row = %ld",
		win_data->window, page_data->vte, win_data->keep_vte_size, column, row);
#  else
	g_debug("@ init_new_page(for %p, vte = %p): Set column = %ld, row = %ld",
		win_data->window, page_data->vte, column, row);
#  endif
#endif

	set_vte_color(page_data->vte, use_default_vte_theme(win_data), win_data->cursor_color, win_data->color, FALSE);

	// set transparent
	set_background_saturation(NULL, 0, win_data->background_saturation, page_data->vte);

	// other settings
	vte_terminal_set_word_chars(VTE_TERMINAL(page_data->vte), win_data->word_chars);
	vte_terminal_set_scrollback_lines(VTE_TERMINAL(page_data->vte), win_data->scrollback_lines);

	// some fixed parameter
	vte_terminal_set_scroll_on_output(VTE_TERMINAL(page_data->vte), FALSE);
	vte_terminal_set_scroll_on_keystroke(VTE_TERMINAL(page_data->vte), TRUE);
	// vte_terminal_set_backspace_binding (VTE_TERMINAL(page_data->vte), VTE_ERASE_ASCII_DELETE);
	// vte_terminal_set_delete_binding (VTE_TERMINAL(page_data->vte), VTE_ERASE_ASCII_DELETE);
	// vte_terminal_set_emulation (VTE_TERMINAL(page_data->vte), "xterm");
#ifdef ENABLE_FIND_STRING
	vte_terminal_search_set_wrap_around (VTE_TERMINAL(page_data->vte), TRUE);
#endif

	set_hyprelink(win_data, page_data);
	set_cursor_blink(win_data, page_data);

	vte_terminal_set_allow_bold(VTE_TERMINAL(page_data->vte), win_data->allow_bold_text);

	vte_terminal_set_audible_bell (VTE_TERMINAL(page_data->vte), win_data->audible_bell);
	vte_terminal_set_visible_bell (VTE_TERMINAL(page_data->vte), win_data->visible_bell);
	// g_debug("init_new_page(): call set_vte_urgent_bell()");
#ifdef ENABLE_BEEP_SINGAL
	set_vte_urgent_bell(win_data, page_data);
#endif
	vte_terminal_set_backspace_binding (VTE_TERMINAL(page_data->vte), win_data->erase_binding);
#ifdef ENABLE_CURSOR_SHAPE
	vte_terminal_set_cursor_shape(VTE_TERMINAL(page_data->vte), win_data->cursor_shape);
#endif
	vte_terminal_set_emulation (VTE_TERMINAL(page_data->vte), win_data->emulate_term);
}
示例#8
0
文件: font.c 项目: NYAMNYAM3/LilyTerm
void apply_font_to_every_vte(GtkWidget *window, gchar *new_font_name, glong column, glong row)
{
#ifdef DETAIL
	g_debug("! Launch apply_font_to_every_vte() with window = %p, new_font_name = %s,"
		" column = %ld, row = %ld", window, new_font_name, column, row);
#endif
#ifdef SAFEMODE
	if ((window==NULL) || (new_font_name==NULL) || (column<1) || (row<1)) return;
#endif
	struct Window *win_data = (struct Window *)g_object_get_data(G_OBJECT(window), "Win_Data");
	// g_debug("Get win_data = %d when apply font to every vte!", win_data);
#ifdef SAFEMODE
	if (win_data==NULL) return;
#endif

	struct Page *page_data = NULL;
	gint i;

	// g_debug("Trying to apply every vte to %dx%d!", column, row);
	// g_debug("Trying to apply font %s to every vte!", new_font_name);

	for (i=0; i<gtk_notebook_get_n_pages(GTK_NOTEBOOK(win_data->notebook)); i++)
	{
		page_data = get_page_data_from_nth_page(win_data, i);
#ifdef SAFEMODE
		if (page_data==NULL) continue;
#endif
		// g_debug("The default font for %d page is: %s (%s)", i, page_data->font_name, new_font_name);
		vte_terminal_set_font_from_string_full(VTE_TERMINAL(page_data->vte),
						       new_font_name,
						       win_data->font_anti_alias);
		vte_terminal_set_size(VTE_TERMINAL(page_data->vte), column, row);
		g_free(page_data->font_name);
		page_data->font_name = g_strdup(new_font_name);
		// g_debug("The new font for %d page is: %s (%s)", i, page_data->font_name, new_font_name);
	}

	// g_debug("* Set hints to HINTS_FONT_BASE!, win_data->window_status = %d", win_data->window_status);
	win_data->hints_type = HINTS_FONT_BASE;

	// win_data->keep_vte_size |= 0x30;
	// g_debug("window_resizable in apply_font_to_every_vte!");
	// window_resizable(window, page_data->vte, 2, 1);
	// g_debug("apply_font_to_every_vte(): launch keep_window_size()!");

	// Don't need to call keep_gtk2_window_size() when fullscreen
	switch (win_data->window_status)
	{
#ifdef USE_GTK2_GEOMETRY_METHOD
		case FULLSCREEN_NORMAL:
		case FULLSCREEN_UNFS_OK:
#  ifdef GEOMETRY
			g_debug("@ apply_font_to_every_vte(): Call keep_gtk2_window_size() with keep_vte_size = %x",
				win_data->keep_vte_size);
#  endif
			keep_gtk2_window_size (win_data, page_data->vte, 0x380);
#endif
#ifdef USE_GTK3_GEOMETRY_METHOD
		case WINDOW_NORMAL:
		case WINDOW_APPLY_PROFILE_NORMAL:
#  ifdef GEOMETRY
			fprintf(stderr, "\033[1;%dm!! apply_font_to_every_vte(win_data %p): Calling keep_gtk3_window_size() with hints_type = %d\n",
				ANSI_COLOR_MAGENTA, win_data, win_data->hints_type);
#  endif
			window_resizable(win_data->window, win_data->current_vte, win_data->hints_type);
			if (win_data->window_status==WINDOW_NORMAL)
				win_data->resize_type = GEOMETRY_AUTOMATIC;
			else
				win_data->resize_type = GEOMETRY_CUSTOM;
			win_data->geometry_width = column;
			win_data->geometry_height = row;
			keep_gtk3_window_size(win_data, TRUE);
#endif
			break;
		default:
			break;
	}
}