Beispiel #1
0
static void
adjust_font_size(GtkWidget *widget, gpointer data, gdouble factor)
{
	VteTerminal *terminal;
        gdouble scale;
        glong char_width, char_height;
	gint columns, rows, owidth, oheight;

	/* Read the screen dimensions in cells. */
	terminal = VTE_TERMINAL(widget);
	columns = vte_terminal_get_column_count(terminal);
	rows = vte_terminal_get_row_count(terminal);

	/* Take into account padding and border overhead. */
	gtk_window_get_size(GTK_WINDOW(data), &owidth, &oheight);
        char_width = vte_terminal_get_char_width (terminal);
        char_height = vte_terminal_get_char_height (terminal);
	owidth -= char_width * columns;
	oheight -= char_height * rows;

	scale = vte_terminal_get_font_scale(terminal);
        vte_terminal_set_font_scale(terminal, scale * factor);

        /* This above call will have changed the char size! */
        char_width = vte_terminal_get_char_width (terminal);
        char_height = vte_terminal_get_char_height (terminal);

	gtk_window_resize(GTK_WINDOW(data),
			  columns * char_width + owidth,
			  rows * char_height + oheight);
}
Beispiel #2
0
static void
ide_terminal_size_allocate (GtkWidget     *widget,
                            GtkAllocation *alloc)
{
  IdeTerminal *self = (IdeTerminal *)widget;
  glong width;
  glong height;
  glong columns;
  glong rows;

  GTK_WIDGET_CLASS (ide_terminal_parent_class)->size_allocate (widget, alloc);

  if ((alloc->width == 0) || (alloc->height == 0))
    return;

  width = vte_terminal_get_char_width (VTE_TERMINAL (self));
  height = vte_terminal_get_char_height (VTE_TERMINAL (self));

  if ((width == 0) || (height == 0))
    return;

  columns = alloc->width / width;
  rows = alloc->height / height;

  if ((columns < 2) || (rows < 2))
    return;

  vte_terminal_set_size (VTE_TERMINAL (self), columns, rows);
}
Beispiel #3
0
static void
resize_window(GtkWidget *widget, guint width, guint height, gpointer data)
{
	VteTerminal *terminal;

	if ((GTK_IS_WINDOW(data)) && (width >= 2) && (height >= 2)) {
                gint owidth, oheight, char_width, char_height, column_count, row_count;
                GtkBorder *inner_border;

		terminal = VTE_TERMINAL(widget);

		gtk_window_get_size(GTK_WINDOW(data), &owidth, &oheight);

		/* Take into account border overhead. */
                char_width = vte_terminal_get_char_width (terminal);
                char_height = vte_terminal_get_char_height (terminal);
                column_count = vte_terminal_get_column_count (terminal);
                row_count = vte_terminal_get_row_count (terminal);
                gtk_widget_style_get (widget, "inner-border", &inner_border, NULL);

                owidth -= char_width * column_count;
                oheight -= char_height * row_count;
                if (inner_border != NULL) {
                        owidth -= inner_border->left + inner_border->right;
                        oheight -= inner_border->top + inner_border->bottom;
                }
		gtk_window_resize(GTK_WINDOW(data),
				  width + owidth, height + oheight);
                gtk_border_free (inner_border);
	}
}
Beispiel #4
0
static void
char_size_realized(GtkWidget *widget, gpointer data)
{
	VteTerminal *terminal;
	GtkWindow *window;
	GdkGeometry geometry;
	guint width, height;
        GtkBorder *inner_border;

	g_assert(GTK_IS_WINDOW(data));
	g_assert(VTE_IS_TERMINAL(widget));

	terminal = VTE_TERMINAL(widget);
	window = GTK_WINDOW(data);
	if (!GTK_WIDGET_REALIZED (window))
		return;

        gtk_widget_style_get (widget, "inner-border", &inner_border, NULL);
	width = vte_terminal_get_char_width (terminal);
	height = vte_terminal_get_char_height (terminal);
	geometry.width_inc = width;
	geometry.height_inc = height;
	geometry.base_width = inner_border ? (inner_border->left + inner_border->right) : 0;
	geometry.base_height = inner_border ? (inner_border->top + inner_border->bottom) : 0;
	geometry.min_width = geometry.base_width + width * 2;
	geometry.min_height = geometry.base_height + height * 2;
        gtk_border_free (inner_border);

	gtk_window_set_geometry_hints(window, widget, &geometry,
				      GDK_HINT_RESIZE_INC |
				      GDK_HINT_BASE_SIZE |
				      GDK_HINT_MIN_SIZE);
}
Beispiel #5
0
static void
resize_window(GtkWidget *widget, guint width, guint height, gpointer data)
{
	VteTerminal *terminal;

	if ((GTK_IS_WINDOW(data)) && (width >= 2) && (height >= 2)) {
		gint owidth, oheight, char_width, char_height, column_count, row_count;
		GtkBorder padding;

		terminal = VTE_TERMINAL(widget);

		gtk_window_get_size(GTK_WINDOW(data), &owidth, &oheight);

		/* Take into account border overhead. */
		char_width = vte_terminal_get_char_width (terminal);
		char_height = vte_terminal_get_char_height (terminal);
		column_count = vte_terminal_get_column_count (terminal);
		row_count = vte_terminal_get_row_count (terminal);
                gtk_style_context_get_padding(gtk_widget_get_style_context(widget),
                                              gtk_widget_get_state_flags(widget),
                                              &padding);

                owidth -= char_width * column_count + padding.left + padding.right;
                oheight -= char_height * row_count + padding.top + padding.bottom;
		gtk_window_resize(GTK_WINDOW(data),
				  width + owidth, height + oheight);
	}
}
Beispiel #6
0
static void termit_set_fonts()
{
    gint page_num = gtk_notebook_get_n_pages(GTK_NOTEBOOK(termit.notebook));
    gint minWidth = 0, minHeight = 0;
    gint i=0;
    for (; i<page_num; ++i) {
        TERMIT_GET_TAB_BY_INDEX(pTab, i);
        vte_terminal_set_font(VTE_TERMINAL(pTab->vte), pTab->style.font);
        GtkBorder* border;
        gtk_widget_style_get(GTK_WIDGET(pTab->vte), "inner-border", &border, NULL);
        gint w = vte_terminal_get_char_width(VTE_TERMINAL(pTab->vte)) * configs.cols + border->left + border->right;
        if (w > minWidth)
            minWidth = w;
        gint h = vte_terminal_get_char_height(VTE_TERMINAL(pTab->vte)) * configs.rows + border->top + border->bottom;
        if (h > minHeight)
            minHeight = h;
    }
    gint oldWidth, oldHeight;
    gtk_window_get_size(GTK_WINDOW(termit.main_window), &oldWidth, &oldHeight);
    
    gint width = (minWidth > oldWidth) ? minWidth : oldWidth;
    gint height = (minHeight > oldHeight) ? minHeight : oldHeight;
    gtk_window_resize(GTK_WINDOW(termit.main_window), width, height);

    GdkGeometry geom;
    geom.min_width = minWidth;
    geom.min_height = minHeight;
    TRACE("width=%d height=%d", width, height);
    TRACE("minWidth=%d minHeight=%d", minWidth, minHeight);
    gtk_window_set_geometry_hints(GTK_WINDOW(termit.main_window), termit.main_window, &geom, GDK_HINT_MIN_SIZE);
}
Beispiel #7
0
gboolean cterm_onclick(GtkWidget* w, GdkEventButton* e, gpointer data) {
    CTerm* term = (CTerm*) data;
    char* match = NULL;
    VteTerminal* vte = cterm_get_current_vte(term);
    GtkBorder* inner_border;
    glong col, row;
    int char_width, char_height;
    int tag;

    if(e->type == GDK_BUTTON_PRESS && e->button == 3) {
        cterm_run_external(term);

    } else if(e->type == GDK_2BUTTON_PRESS && e->button == 1) {
        char_width = vte_terminal_get_char_width(VTE_TERMINAL(vte));
        char_height = vte_terminal_get_char_height(VTE_TERMINAL(vte));

        gtk_widget_style_get(GTK_WIDGET(vte), "inner-border", &inner_border, NULL);
        row = (e->y - (inner_border ? inner_border->top : 0)) / char_height;
        col = (e->x - (inner_border ? inner_border->left : 0)) / char_width;
        gtk_border_free(inner_border);

        match = vte_terminal_match_check(vte, col, row, &tag);
        if(match != NULL) {
            cterm_open_url(term, match);
            free(match);
        }
    }

    return FALSE;
}
static void
size_allocate_cb (VteTerminal    *terminal,
                  GtkAllocation  *alloc,
                  GbTerminalView *self)
{
  glong width;
  glong height;
  glong columns;
  glong rows;

  g_assert (VTE_IS_TERMINAL (terminal));
  g_assert (alloc != NULL);
  g_assert (GB_IS_TERMINAL_VIEW (self));

  if ((alloc->width == 0) || (alloc->height == 0))
    return;

  width = vte_terminal_get_char_width (terminal);
  height = vte_terminal_get_char_height (terminal);

  if ((width == 0) || (height == 0))
    return;

  columns = alloc->width / width;
  rows = alloc->height / height;

  if ((columns < 2) || (rows < 2))
    return;

  vte_terminal_set_size (terminal, columns, rows);
}
Beispiel #9
0
static char *check_match(VteTerminal *vte, int event_x, int event_y) {
    int xpad, ypad, tag;
    get_vte_padding(vte, &xpad, &ypad);
    return vte_terminal_match_check(vte,
                                    (event_x - ypad) / vte_terminal_get_char_width(vte),
                                    (event_y - ypad) / vte_terminal_get_char_height(vte),
                                    &tag);
}
Beispiel #10
0
// set the window hints information
void window_resizable(GtkWidget *window, GtkWidget *vte, gint set_hints_inc)
{
#ifdef DEFENSIVE
	if ((window==NULL) || (vte==NULL)) return;
#endif
#ifdef DETAIL
	g_debug("! Launch window_resizable() with window = %p, vte = %p, set_hints_inc = %d",
		window, vte, set_hints_inc);
#endif

	// DIRTY HACK: don't run window_resizable too much times before window is shown!
	if ((set_hints_inc != 1) && (gtk_widget_get_mapped(window) == FALSE)) return;

	// vte=NULL when creating a new root window with drag & drop.
	// if (vte==NULL) return;

	GdkGeometry hints = {0};
	// g_debug("Trying to get padding...");
	vte_terminal_get_padding (VTE_TERMINAL(vte), &(hints.base_width), &(hints.base_height));
	// g_debug("hints.base_width = %d, hints.base_height = %d", hints.base_width, hints.base_height);

	switch (set_hints_inc)
	{
		case 1:
			hints.width_inc = vte_terminal_get_char_width(VTE_TERMINAL(vte));
			hints.height_inc = vte_terminal_get_char_height(VTE_TERMINAL(vte));
			break;
		case 2:
			hints.width_inc = 1;
			hints.height_inc = 1;
			break;
	}

	// g_debug("hints.width_inc = %d, hints.height_inc = %d",
	//	hints.width_inc, hints.height_inc);

	// // minsize = -1: the size of vte can NOT be changed.
	// if (minsize == -1)
	// {
	//	hints.min_width = minsize;
	//	hints.min_height = minsize;
	// }
	// else
	// {
		hints.min_width = hints.base_width + hints.width_inc;
		hints.min_height = hints.base_height + hints.height_inc;
	// }

	// g_debug("Tring to set geometry on %p, and set_hints_inc = %d", vte, set_hints_inc);
	gtk_window_set_geometry_hints (GTK_WINDOW (window), GTK_WIDGET (vte), &hints,
					GDK_HINT_RESIZE_INC | GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE);

	//g_debug("current the size of vte %p whith hinting = %ld x %ld",
	//			vte,
	//			vte_terminal_get_column_count(VTE_TERMINAL(vte)),
	//			vte_terminal_get_row_count(VTE_TERMINAL(vte)));
}
Beispiel #11
0
static void
mud_subwindow_set_size_force_grid (MudSubwindow *window,
                                   VteTerminal *screen,
                                   gboolean        even_if_mapped,
                                   int             force_grid_width,
                                   int             force_grid_height)
{
    /* TODO: Missing get_padding in new VTE; maybe we can just use vte_terminal_set_size? */
#if 0
#warning Reimplement mud_subwindow size forcing
    /* Owen's hack from gnome-terminal */
    GtkWidget *widget;
    GtkWidget *app;
    GtkRequisition toplevel_request;
    GtkRequisition widget_request;
    int w, h;
    int char_width;
    int char_height;
    int grid_width;
    int grid_height;
    int xpad;
    int ypad;

    g_return_if_fail(MUD_IS_SUBWINDOW(window));

    /* be sure our geometry is up-to-date */
    mud_subwindow_update_geometry (window);
    widget = GTK_WIDGET (screen);

    app = window->priv->window;

    gtk_widget_size_request (app, &toplevel_request);
    gtk_widget_size_request (widget, &widget_request);

    w = toplevel_request.width - widget_request.width;
    h = toplevel_request.height - widget_request.height;

    char_width = vte_terminal_get_char_width (screen);
    char_height = vte_terminal_get_char_height (screen);

    grid_width = vte_terminal_get_column_count (screen);
    grid_height = vte_terminal_get_row_count (screen);

    if (force_grid_width >= 0)
        grid_width = force_grid_width;
    if (force_grid_height >= 0)
        grid_height = force_grid_height;

    vte_terminal_get_padding (VTE_TERMINAL (screen), &xpad, &ypad);

    w += xpad * 2 + char_width * grid_width;
    h += ypad * 2 + char_height * grid_height;

    if (even_if_mapped && gtk_widget_get_mapped (app)) {
        gtk_window_resize (GTK_WINDOW (app), w, h);
    }
}
Beispiel #12
0
static int termit_cursor_under_match(const GdkEventButton* ev, char** matchedText)
{
    gint page = gtk_notebook_get_current_page(GTK_NOTEBOOK(termit.notebook));
    TERMIT_GET_TAB_BY_INDEX2(pTab, page, -1);

    glong column = ((glong) (ev->x) / vte_terminal_get_char_width(VTE_TERMINAL(pTab->vte)));
    glong row = ((glong) (ev->y) / vte_terminal_get_char_height(VTE_TERMINAL(pTab->vte)));
    int tag = -1;
    *matchedText = vte_terminal_match_check(VTE_TERMINAL(pTab->vte), column, row, &tag);
    TRACE("column=%ld row=%ld matchedText=[%s] tag=%d", column, row, *matchedText, tag);
    return tag;
}
Beispiel #13
0
static gboolean termomix_button_press(GtkWidget *widget,
        GdkEventButton *button_event, gpointer user_data) {
    glong column, row;
    gint tag;

    if (button_event->type != GDK_BUTTON_PRESS)
        return FALSE;


    /* Get the column and row relative to pointer position */
    column = ((glong) (button_event->x) / vte_terminal_get_char_width(
            VTE_TERMINAL(termomix.term->vte)));
    row = ((glong) (button_event->y) / vte_terminal_get_char_height(
            VTE_TERMINAL(termomix.term->vte)));
    termomix.current_match = vte_terminal_match_check(
            VTE_TERMINAL(termomix.term->vte), column, row, &tag);

    /* Left button: open the URL if any */
    if (button_event->button == 1 &&
            ((button_event->state & termomix.open_url_accelerator) ==
            termomix.open_url_accelerator) && termomix.current_match) {
        termomix_open_url(NULL, NULL);
        return TRUE;
    }

    /* Right button: show the popup menu */
    if (button_event->button == 3) {
        GtkMenu *menu;
        menu = GTK_MENU (widget);

        if (termomix.current_match) {
            /* Show the extra options in the menu */
            gtk_widget_show(termomix.item_open_link);
            gtk_widget_show(termomix.item_copy_link);
            gtk_widget_show(termomix.open_link_separator);
        } else {
            /* Hide all the options */
            gtk_widget_hide(termomix.item_open_link);
            gtk_widget_hide(termomix.item_copy_link);
            gtk_widget_hide(termomix.open_link_separator);
        }

        gtk_menu_popup (menu, NULL, NULL, NULL, NULL, button_event->button,
                button_event->time);

        return TRUE;
    }
    return FALSE;
}
Beispiel #14
0
/* button event handler */
gboolean event_button(GtkWidget *widget, GdkEventButton *button_event) {

  int ret = 0;
  gchar *match;

  if(button_event->button == 1) {
    match = vte_terminal_match_check(VTE_TERMINAL(widget), 
        button_event->x / vte_terminal_get_char_width (VTE_TERMINAL (widget)),
        button_event->y / vte_terminal_get_char_height (VTE_TERMINAL (widget)),
        &ret);
    if (match) {
      launch_url(match);
      return TRUE;
    }
  }
  return FALSE;
}
Beispiel #15
0
static CursorMatch term_cursor_match_pattern(GdkEventButton* event)
{
    int tag = -1;
    
    gint page = gtk_notebook_get_current_page(GTK_NOTEBOOK(tabbar));
    GList *children = gtk_container_get_children(GTK_CONTAINER(gtk_notebook_get_nth_page(GTK_NOTEBOOK(tabbar), page)));
    GtkWidget *vte = GTK_WIDGET(children->data);

    glong column = ((glong) (event->x) / vte_terminal_get_char_width(VTE_TERMINAL(vte)));
    glong row = ((glong) (event->y) / vte_terminal_get_char_height(VTE_TERMINAL(vte)));
    
    char* current_match = vte_terminal_match_check(VTE_TERMINAL(vte), column, row, &tag);

    CursorMatch match;

    match.tag = tag;
    match.text = current_match;
    
    return match;
}
Beispiel #16
0
static void
mud_subwindow_update_geometry (MudSubwindow *window)
{
    GtkWidget *widget = window->priv->terminal;
    GdkGeometry hints;
    gint char_width;
    gint char_height;
    gint xpad, ypad;

    if(gtk_widget_get_mapped(window->priv->window))
    {
        char_width = vte_terminal_get_char_width (VTE_TERMINAL(widget));
        char_height = vte_terminal_get_char_height (VTE_TERMINAL(widget));

        vte_terminal_get_padding (VTE_TERMINAL (window->priv->terminal), &xpad, &ypad);

        hints.base_width = xpad;
        hints.base_height = ypad;

#define MIN_WIDTH_CHARS 4
#define MIN_HEIGHT_CHARS 2

        hints.width_inc = char_width;
        hints.height_inc = char_height;

        /* min size is min size of just the geometry widget, remember. */
        hints.min_width = hints.base_width + hints.width_inc * MIN_WIDTH_CHARS;
        hints.min_height = hints.base_height + hints.height_inc * MIN_HEIGHT_CHARS;

        gtk_window_set_geometry_hints (GTK_WINDOW (window->priv->window),
                widget,
                &hints,
                GDK_HINT_RESIZE_INC |
                GDK_HINT_MIN_SIZE |
                GDK_HINT_BASE_SIZE);
    }
#endif
}
Beispiel #17
0
static int
button_pressed(GtkWidget *widget, GdkEventButton *event, gpointer data)
{
	VteTerminal *terminal;
	char *match;
	int tag;
        GtkBorder *inner_border;
        int char_width, char_height;

	switch (event->button) {
	case 3:
		terminal = VTE_TERMINAL(widget);

                gtk_widget_style_get (widget, "inner-border", &inner_border, NULL);
                char_width = vte_terminal_get_char_width (terminal);
                char_height = vte_terminal_get_char_height (terminal);
		match = vte_terminal_match_check(terminal,
						 (event->x - (inner_border ? inner_border->left : 0)) / char_width,
						 (event->y - (inner_border ? inner_border->top : 0)) / char_height,
						 &tag);
                gtk_border_free (inner_border);
		if (match != NULL) {
			g_print("Matched `%s' (%d).\n", match, tag);
			g_free(match);
			if (GPOINTER_TO_INT(data) != 0) {
				vte_terminal_match_remove(terminal, tag);
			}
		}
		break;
	case 1:
	case 2:
	default:
		break;
	}
	return FALSE;
}
Beispiel #18
0
/* setup the whacky geometry hints for gtk */
static void tab_geometry_hints(term *t) {
  // I dont need to call this every time, since the char width only changes
  // once, maybe I'll make hints and border global and reuse them
  GdkGeometry hints;
  GtkBorder *border;
  gint char_width, char_height;
  gtk_widget_style_get(GTK_WIDGET(t->vte), "inner-border", &border, NULL);

  char_width = vte_terminal_get_char_width(VTE_TERMINAL(t->vte));
  char_height = vte_terminal_get_char_height(VTE_TERMINAL(t->vte));

  hints.min_width = char_width + border->left + border->right;
  hints.min_height = char_height + border->top + border->bottom;
  hints.base_width = border->left + border->right;
  hints.base_height = border->top + border->bottom;
  hints.width_inc = char_width;
  hints.height_inc = char_height;

  gtk_window_set_geometry_hints(
      GTK_WINDOW(t->w->win),
      GTK_WIDGET(t->vte),
      &hints,
      GDK_HINT_RESIZE_INC | GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE);
}
Beispiel #19
0
static void adjust_font_size (GtkWidget *widget, gpointer data, gint howmuch)
{
    DEBUG_FUNCTION ("adjust_font_size");
    DEBUG_ASSERT (widget != NULL);
    DEBUG_ASSERT (data != NULL);

    VteTerminal *terminal;
    PangoFontDescription *desired;
    gint newsize;
    gint columns, rows, owidth, oheight;

    /* Read the screen dimensions in cells. */
    terminal = VTE_TERMINAL(widget);
    columns = vte_terminal_get_column_count (terminal);
    rows = vte_terminal_get_row_count (terminal);

    /* Take into account padding and border overhead. */
    gtk_window_get_size(GTK_WINDOW(data), &owidth, &oheight);
    owidth -= vte_terminal_get_char_width (terminal) * columns;
    oheight -= vte_terminal_get_char_height (terminal) * rows;

    /* Calculate the new font size. */
    desired = pango_font_description_copy (vte_terminal_get_font(terminal));
    newsize = pango_font_description_get_size (desired) / PANGO_SCALE;
    newsize += howmuch;
    pango_font_description_set_size (desired, CLAMP(newsize, 4, 144) * PANGO_SCALE);

    /* Change the font, then resize the window so that we have the same
     * number of rows and columns. */
    vte_terminal_set_font (terminal, desired);
    /*gtk_window_resize (GTK_WINDOW(data),
              columns * terminal->char_width + owidth,
              rows * terminal->char_height + oheight);*/

    pango_font_description_free (desired);
}
Beispiel #20
0
static VALUE
term_get_char_height(VALUE self)
{
    return LONG2NUM(vte_terminal_get_char_height(RVAL2TERM(self)));
}
Beispiel #21
0
static GtkWidget*
create_new_window (GtkApplication *application,
                   GVariantDict   *options)
{
    dg_lmem gchar* command = NULL;
    dg_lmem gchar* title = NULL;
    gboolean opt_show_title;
    gboolean opt_update_title;
    gboolean opt_no_headerbar;

    g_object_get (dwt_settings_get_instance (),
                  "show-title", &opt_show_title,
                  "update-title", &opt_update_title,
                  "no-header-bar", &opt_no_headerbar,
                  "command", &command,
                  "title", &title,
                  NULL);

    const gchar *opt_command = command;
    const gchar *opt_title   = title;
    const gchar *opt_workdir = NULL;

    if (options) {
        gboolean opt_no_auto_title = FALSE;
        g_variant_dict_lookup (options, "title-on-maximize", "b", &opt_show_title);
        g_variant_dict_lookup (options, "no-header-bar", "b", &opt_no_headerbar);
        g_variant_dict_lookup (options, "no-auto-title", "b", &opt_no_auto_title);
        g_variant_dict_lookup (options, "workdir", "&s", &opt_workdir);
        g_variant_dict_lookup (options, "command", "&s", &opt_command);
        g_variant_dict_lookup (options, "title",   "&s", &opt_title);
        if (opt_no_auto_title)
            opt_update_title = FALSE;
    }
    if (!opt_workdir) opt_workdir = g_get_home_dir ();
    if (!opt_command) opt_command = guess_shell ();

    /*
     * Title either comes from the default value of the "title" setting,
     * or from the command line flag, but should never be NULL at this
     * point.
     */
    g_assert (opt_title);

    dg_lerr GError *gerror = NULL;
    gint command_argv_len = 0;
    gchar **command_argv = NULL;

    if (!g_shell_parse_argv (opt_command,
                             &command_argv_len,
                             &command_argv,
                             &gerror))
    {
        g_printerr ("%s: coult not parse command: %s\n",
                    __func__, gerror->message);
        return NULL;
    }

    GtkWidget *window = gtk_application_window_new (application);
    gtk_widget_set_visual (window,
                           gdk_screen_get_system_visual (gtk_widget_get_screen (window)));
    gtk_application_window_set_show_menubar (GTK_APPLICATION_WINDOW (window),
                                             FALSE);
    gtk_window_set_title (GTK_WINDOW (window), opt_title);
    gtk_window_set_hide_titlebar_when_maximized (GTK_WINDOW (window),
                                                 !opt_show_title);

    g_action_map_add_action_entries (G_ACTION_MAP (window), win_actions,
                                     G_N_ELEMENTS (win_actions), window);

    VteTerminal *vtterm = VTE_TERMINAL (vte_terminal_new ());
    configure_term_widget (vtterm, options);
    term_char_size_changed (vtterm,
                            vte_terminal_get_char_width (vtterm),
                            vte_terminal_get_char_height (vtterm),
                            window);

    g_signal_connect (G_OBJECT (window), "notify::has-toplevel-focus",
                      G_CALLBACK (window_has_toplevel_focus_notified),
                      vtterm);

    g_signal_connect (G_OBJECT (vtterm), "char-size-changed",
                      G_CALLBACK (term_char_size_changed), window);
    g_signal_connect (G_OBJECT (vtterm), "child-exited",
                      G_CALLBACK (term_child_exited), window);
    g_signal_connect (G_OBJECT (vtterm), "bell",
                      G_CALLBACK (term_beeped), window);
    g_signal_connect (G_OBJECT (vtterm), "button-release-event",
                      G_CALLBACK (term_mouse_button_released),
                      setup_popover (vtterm));

    /*
     * Propagate title changes to the window.
     */
    if (opt_update_title)
        g_object_bind_property (G_OBJECT (vtterm), "window-title",
                                G_OBJECT (window), "title",
                                G_BINDING_DEFAULT);

    if (!opt_no_headerbar)
        setup_header_bar (window, vtterm, opt_show_title);

    gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (vtterm));
    gtk_widget_set_receives_default (GTK_WIDGET (vtterm), TRUE);

    /* We need to realize and show the window for it to have a valid XID */
    gtk_widget_show_all (window);

    gchar **command_env = g_get_environ ();
#ifdef GDK_WINDOWING_X11
    if (GDK_IS_X11_SCREEN (gtk_widget_get_screen (window))) {
        GdkWindow *gdk_window = gtk_widget_get_window (window);
        if (gdk_window) {
            gchar window_id[NDIGITS10(unsigned long)];
            snprintf (window_id,
                      sizeof (window_id),
                      "%lu",
                      GDK_WINDOW_XID (gdk_window));
            command_env = g_environ_setenv (command_env,
                                            "WINDOWID",
                                            window_id,
                                            TRUE);
        } else {
            g_printerr ("No window, cannot set $WINDOWID!\n");
        }
    }
Beispiel #22
0
static gboolean
term_mouse_button_released (VteTerminal    *vtterm,
                            GdkEventButton *event,
                            gpointer        userdata)
{
    g_free (last_match_text);
    last_match_text = NULL;

    glong row = (glong) (event->y) / vte_terminal_get_char_height (vtterm);
    glong col = (glong) (event->x) / vte_terminal_get_char_width  (vtterm);

    gint match_tag;
    dg_lmem gchar* match = vte_terminal_match_check (vtterm, col, row, &match_tag);

    if (match && event->button == 1) {
		if (CHECK_FLAGS (event->state, GDK_CONTROL_MASK)) {
			dg_lerr GError *gerror = NULL;
			if (!gtk_show_uri (NULL, match, event->time, &gerror))
				g_printerr ("Could not open URL: %s\n", gerror->message);
			return FALSE;
		} else if (g_regex_match (image_regex, match, 0, NULL)) {
			/* Show picture in a popover */
			GdkRectangle rect;
			rect.height = vte_terminal_get_char_height (vtterm);
			rect.width = vte_terminal_get_char_width (vtterm);
			rect.y = rect.height * row;
			rect.x = rect.width * col;

			GtkWidget* popover = make_popover_for_image_url (vtterm, match);
			gtk_popover_set_pointing_to (GTK_POPOVER (popover), &rect);
			return FALSE;
		}
    }


    if (event->button == 3 && userdata != NULL) {
        GdkRectangle rect;
        rect.height = vte_terminal_get_char_height (vtterm);
        rect.width = vte_terminal_get_char_width (vtterm);
        rect.y = rect.height * row;
        rect.x = rect.width * col;
        gtk_popover_set_pointing_to (GTK_POPOVER (userdata), &rect);

        GActionMap *actions = G_ACTION_MAP (gtk_widget_get_ancestor (GTK_WIDGET (vtterm),
                                                                     GTK_TYPE_WINDOW));
        g_simple_action_set_enabled (G_SIMPLE_ACTION (g_action_map_lookup_action (actions,
                                                                                  "copy")),
                                    vte_terminal_get_has_selection (vtterm));
        g_simple_action_set_enabled (G_SIMPLE_ACTION (g_action_map_lookup_action (actions,
                                                                                  "open-url")),
                                     match != NULL);
        g_simple_action_set_enabled (G_SIMPLE_ACTION (g_action_map_lookup_action (actions,
                                                                                  "copy-url")),
                                     match != NULL);
        if (match) {
            last_match_text = match;
            match = NULL;
        }

        gtk_widget_show_all (GTK_WIDGET (userdata));

        return TRUE;
    }

    return FALSE;
}
Beispiel #23
0
console_t *uimon_window_open(void)
{
    GtkWidget *scrollbar, *horizontal_container;
    GdkGeometry hints;

    if (fixed.window == NULL) {
        fixed.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_title(GTK_WINDOW(fixed.window), "VICE monitor");
        gtk_window_set_position(GTK_WINDOW(fixed.window), GTK_WIN_POS_CENTER);
        gtk_widget_set_app_paintable(fixed.window, TRUE);
        gtk_window_set_deletable(GTK_WINDOW(fixed.window), TRUE);
        fixed.term = vte_terminal_new();
        vte_terminal_set_scrollback_lines (VTE_TERMINAL(fixed.term), 1000);
        vte_terminal_set_scroll_on_output (VTE_TERMINAL(fixed.term), TRUE);

        /* allowed window widths are base_width + width_inc * N
         * allowed window heights are base_height + height_inc * N
         */
        hints.width_inc = vte_terminal_get_char_width (VTE_TERMINAL(fixed.term));
        hints.height_inc = vte_terminal_get_char_height (VTE_TERMINAL(fixed.term));
        /* min size should be multiple of .._inc, else we get funky effects */
        hints.min_width = hints.width_inc;
        hints.min_height = hints.height_inc;
        /* base size should be multiple of .._inc, else we get funky effects */
        hints.base_width = hints.width_inc;
        hints.base_height = hints.height_inc;
        gtk_window_set_geometry_hints (GTK_WINDOW (fixed.window),
                                     fixed.term,
                                     &hints,
                                     GDK_HINT_RESIZE_INC |
                                     GDK_HINT_MIN_SIZE |
                                     GDK_HINT_BASE_SIZE);
#if GTK_CHECK_VERSION (2, 91, 1)
        {
            glong width, height;
            get_terminal_size_in_chars(VTE_TERMINAL(fixed.term), &width, &height);
            gtk_window_resize_to_geometry (GTK_WINDOW (fixed.window), width, height);
        }
#endif
        scrollbar = gtk_vscrollbar_new(vte_terminal_get_adjustment (VTE_TERMINAL(fixed.term)));
        horizontal_container = gtk_hbox_new(FALSE, 0);
        gtk_container_add(GTK_CONTAINER(fixed.window), horizontal_container);
        gtk_container_add(GTK_CONTAINER(horizontal_container), fixed.term);
        gtk_container_add(GTK_CONTAINER(horizontal_container), scrollbar);

        g_signal_connect(G_OBJECT(fixed.window), "delete-event",
            G_CALLBACK(close_window), &fixed.input_buffer);

        g_signal_connect(G_OBJECT(fixed.term), "key-press-event", 
            G_CALLBACK(key_press_event), &fixed.input_buffer);

        g_signal_connect(G_OBJECT(fixed.term), "button-press-event", 
            G_CALLBACK(button_press_event), &fixed.input_buffer);

        g_signal_connect (fixed.term, "text-modified",
            G_CALLBACK (screen_resize_window_cb), NULL);

        vte_console.console_can_stay_open = 1;
    }
    return uimon_window_resume();
}
Beispiel #24
0
void new_window(GtkApplication *app, gchar **argv, gint argc)
{
    GtkWidget* window;
    GtkWidget* box;
    GdkPixbuf* icon;
    GdkGeometry geo_hints;
    GtkIconTheme* icon_theme;
    GError* error = NULL;

    /* Variables for parsed command-line arguments */
    char* command = NULL;
    char* directory = NULL;
    gboolean keep = FALSE;
    char* name = NULL;
    char* title = NULL;

    parse_arguments(argc, argv, &command, &directory, &keep, &name, &title);

    /* Create window */
    window = gtk_application_window_new(GTK_APPLICATION(app));
    g_signal_connect(window, "delete-event", G_CALLBACK(window_close), app);

    gtk_window_set_wmclass(GTK_WINDOW (window), name ? name : "tinyterm", "TinyTerm");
    gtk_window_set_title(GTK_WINDOW (window), title ? title : "TinyTerm");

    /* Set window icon supplied by an icon theme */
    icon_theme = gtk_icon_theme_get_default();
    icon = gtk_icon_theme_load_icon(icon_theme, "terminal", 48, 0, &error);
    if (error)
        g_error_free(error);
    if (icon)
        gtk_window_set_icon(GTK_WINDOW (window), icon);

    /* Create main box */
    box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
    gtk_container_add(GTK_CONTAINER (window), box);

    /* Create vte terminal widget */
    GtkWidget* vte_widget = vte_terminal_new();
    gtk_box_pack_start(GTK_BOX (box), vte_widget, TRUE, TRUE, 0);
    VteTerminal* vte = VTE_TERMINAL (vte_widget);
    if (!keep)
        g_signal_connect(vte, "child-exited", G_CALLBACK (vte_exit_cb), window);
    g_signal_connect(vte, "key-press-event", G_CALLBACK (key_press_cb), NULL);
    #ifdef TINYTERM_URGENT_ON_BELL
    g_signal_connect(vte, "bell", G_CALLBACK (window_urgency_hint_cb), NULL);
    g_signal_connect(window, "focus-in-event",  G_CALLBACK (window_focus_cb), NULL);
    g_signal_connect(window, "focus-out-event", G_CALLBACK (window_focus_cb), NULL);
    #endif // TINYTERM_URGENT_ON_BELL
    #ifdef TINYTERM_DYNAMIC_WINDOW_TITLE
    if (!title)
        g_signal_connect(vte, "window-title-changed", G_CALLBACK (window_title_cb), NULL);
    #endif // TINYTERM_DYNAMIC_WINDOW_TITLE

    /* Apply geometry hints to handle terminal resizing */
    geo_hints.base_width  = vte_terminal_get_char_width(vte);
    geo_hints.base_height = vte_terminal_get_char_height(vte);
    geo_hints.min_width   = vte_terminal_get_char_width(vte);
    geo_hints.min_height  = vte_terminal_get_char_height(vte);
    geo_hints.width_inc   = vte_terminal_get_char_width(vte);
    geo_hints.height_inc  = vte_terminal_get_char_height(vte);
    gtk_window_set_geometry_hints(GTK_WINDOW (window), vte_widget, &geo_hints,
                                  GDK_HINT_RESIZE_INC | GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE);

    vte_config(vte);
    vte_spawn(vte, directory, command, NULL);

    /* cleanup */
    g_free(command);
    g_free(directory);
    g_free(name);
    g_free(title);

    /* Show widgets and run main loop */
    gtk_widget_show_all(window);
}
Beispiel #25
0
// set the window hints information
void window_resizable(GtkWidget *window, GtkWidget *vte, Hints_Type hints_type)
{
#ifdef DETAIL
	fprintf(stderr, "\033[1;31m** Launch window_resizable() with window = %p, vte = %p, hints_type = %d\033[0m\n",
		window, vte, hints_type);
#endif
#ifdef SAFEMODE
	if ((window==NULL) || (vte==NULL)) return;
#endif

	// DIRTY HACK: don't run window_resizable too much times before window is shown!
	if ((hints_type != HINTS_FONT_BASE) && (gtk_widget_get_mapped(window) == FALSE)) return;

	// vte=NULL when creating a new root window with drag & drop.
	// if (vte==NULL) return;

	GdkGeometry hints = {0};
	// g_debug("Trying to get padding...");
	vte_terminal_get_padding (VTE_TERMINAL(vte), &(hints.base_width), &(hints.base_height));
	// g_debug("hints.base_width = %d, hints.base_height = %d", hints.base_width, hints.base_height);

	switch (hints_type)
	{
		case HINTS_FONT_BASE:
			hints.width_inc = vte_terminal_get_char_width(VTE_TERMINAL(vte));
			hints.height_inc = vte_terminal_get_char_height(VTE_TERMINAL(vte));
			break;
		case HINTS_NONE:
			hints.width_inc = 1;
			hints.height_inc = 1;
			break;
#if defined(USE_GTK3_GEOMETRY_METHOD) || defined(UNIT_TEST)
		case HINTS_SKIP_ONCE:
			return;
#endif
	}

	// g_debug("hints.width_inc = %d, hints.height_inc = %d",
	//	hints.width_inc, hints.height_inc);

	// // minsize = -1: the size of vte can NOT be changed.
	// if (minsize == -1)
	// {
	//	hints.min_width = minsize;
	//	hints.min_height = minsize;
	// }
	// else
	// {
#if defined(USE_GTK3_GEOMETRY_METHOD) || defined(UNIT_TEST)
		gint min_width = 0, min_height = 0;
		struct Window *win_data = (struct Window *)g_object_get_data(G_OBJECT(window), "Win_Data");
		struct Page *page_data = (struct Page *)g_object_get_data(G_OBJECT(vte), "Page_Data");
		get_hint_min_size(win_data->notebook, page_data->scroll_bar, &min_width, &min_height);
		hints.min_width = hints.base_width + ((int)(min_width/hints.width_inc)+1)*hints.width_inc;
		hints.min_height = hints.base_height + ((int)(min_height/hints.height_inc)+1)*hints.height_inc;
#  ifdef GEOMETRY
		fprintf(stderr, "\033[1;37m** window_resizable(win_data %p): window = %p, vte = %p, hints_type = %d\033[0m\n",
			win_data, window, vte, hints_type);
#  endif
#endif
#ifdef USE_GTK2_GEOMETRY_METHOD
		hints.min_width = hints.base_width + hints.width_inc;
		hints.min_height = hints.base_height + hints.height_inc;
#endif
	// }
#ifdef GEOMETRY
	g_debug("@ hint data: hints.width_inc = %d, hints.height_inc = %d, hints.base_width = %d, "
		"@ hints.base_height = %d, hints.min_width = %d, hints.min_height = %d",
		hints.width_inc, hints.height_inc, hints.base_width, hints.base_height, hints.min_width, hints.min_height);
#endif

	// g_debug("Tring to set geometry on %p, and hints_type = %d", vte, hints_type);
	gtk_window_set_geometry_hints (GTK_WINDOW (window), GTK_WIDGET (vte), &hints,
				       GDK_HINT_RESIZE_INC | GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE);

	//g_debug("current the size of vte %p whith hinting = %ld x %ld",
	//			vte,
	//			vte_terminal_get_column_count(VTE_TERMINAL(vte)),
	//			vte_terminal_get_row_count(VTE_TERMINAL(vte)));
}
Beispiel #26
0
static VALUE
rg_char_height(VALUE self)
{
    return LONG2NUM(vte_terminal_get_char_height(_SELF(self)));
}
Beispiel #27
0
static int button_press_cb (GtkWidget *widget, GdkEventButton *event, gpointer data)
{
    DEBUG_FUNCTION ("button_press_cb");
    DEBUG_ASSERT (data != NULL);

    VteTerminal *terminal;
    tilda_term *tt;
    gchar *match;
    gint tag;
    gint xpad, ypad;
    gchar *cmd;
    gchar *web_browser_cmd;
    gboolean ret = FALSE;

    tt = TILDA_TERM(data);

    switch (event->button)
    {
        case 3: /* Right Click */
            popup_menu (tt->tw, tt);
            break;
        case 2: /* Middle Click */
            break;
        case 1: /* Left Click */
            terminal  = VTE_TERMINAL(tt->vte_term);
            GtkBorder border;
            gtk_widget_style_get (GTK_WIDGET (terminal),
                "inner-border", &border, NULL);
            xpad = border.left;
            ypad = border.bottom;
            match = vte_terminal_match_check (terminal,
                    (event->x - ypad) /
                    vte_terminal_get_char_width (terminal),
                    (event->y - ypad) /
                    vte_terminal_get_char_height (terminal),
                    &tag);

            /* Check if we can launch a web browser, and do so if possible */
            if ((event->state & GDK_CONTROL_MASK) && match != NULL)
            {
#if DEBUG
                g_print ("Got a Ctrl+Left Click -- Matched: `%s' (%d)\n", match, tag);
#endif
                web_browser_cmd = g_strescape (config_getstr ("web_browser"), NULL);
                cmd = g_strdup_printf ("%s %s", web_browser_cmd, match);
#if DEBUG
                g_print ("Launching command: `%s'\n", cmd);
#endif
                ret = g_spawn_command_line_async(cmd, NULL);

                /* Check that the command launched */
                if (!ret)
                {
                    g_printerr (_("Failed to launch the web browser. The command was `%s'\n"), cmd);
                    TILDA_PERROR ();
                }

                g_free (cmd);
            }

            /* Always free match if it is non NULL */
            if (match)
                g_free (match);

            break;
        default:
            break;
    }

    return FALSE;
}