/* FIXME remove when gtknotebook's func for this becomes public, bug #.... */
static EphyNotebook *
find_notebook_at_pointer (gint abs_x, gint abs_y)
{
    GdkWindow *win_at_pointer, *toplevel_win;
    gpointer toplevel = NULL;
    gint x, y;

    /* FIXME multi-head */
    win_at_pointer = gdk_window_at_pointer (&x, &y);
    if (win_at_pointer == NULL)
    {
        /* We are outside all windows containing a notebook */
        return NULL;
    }

    toplevel_win = gdk_window_get_toplevel (win_at_pointer);

    /* get the GtkWidget which owns the toplevel GdkWindow */
    gdk_window_get_user_data (toplevel_win, &toplevel);

    /* toplevel should be an EphyWindow */
    if (toplevel != NULL && EPHY_IS_WINDOW (toplevel))
    {
        return EPHY_NOTEBOOK (ephy_window_get_notebook
                              (EPHY_WINDOW (toplevel)));
    }

    return NULL;
}
static void
attach_window (EphyExtension *ext,
               EphyWindow *window)
{
    GtkWidget *notebook;
    gulong handler_id;

    notebook = ephy_window_get_notebook (window);

    handler_id = g_signal_connect (notebook, "button-press-event",
                                   G_CALLBACK (button_press_event_cb), window);

    g_object_set_qdata (G_OBJECT (notebook), HANDLER_ID,
                        GUINT_TO_POINTER (handler_id));
}
static void
detach_window (EphyExtension *ext,
               EphyWindow *window)
{
    GtkWidget *notebook;
    gulong handler_id;
    gpointer data;

    notebook = ephy_window_get_notebook (window);

    data = g_object_get_qdata (G_OBJECT (notebook), HANDLER_ID);

    if (data == NULL)
        return;

    handler_id = GPOINTER_TO_UINT (data);

    g_signal_handler_disconnect (notebook, handler_id);
}
Exemplo n.º 4
0
static void
window_added_cb (GtkApplication *application,
		 GtkWindow *window,
		 EphySession *session)
{
	GtkWidget *notebook;
	EphyWindow *ephy_window;

	ephy_session_save (session, SESSION_STATE);

	if (!EPHY_IS_WINDOW (window))
		return;

	ephy_window = EPHY_WINDOW (window);

	notebook = ephy_window_get_notebook (ephy_window);
	g_signal_connect (notebook, "page-added",
			  G_CALLBACK (notebook_page_added_cb), session);
	g_signal_connect (notebook, "page-removed",
			  G_CALLBACK (notebook_page_removed_cb), session);
	g_signal_connect (notebook, "page-reordered",
			  G_CALLBACK (notebook_page_reordered_cb), session);

	/* Set unique identifier as role, so that on restore, the WM can
	 * place the window on the right workspace
	 */

	if (gtk_window_get_role (window) == NULL)
	{
		/* I guess rand() is unique enough, otherwise we could use
		 * time + pid or something
		 */
		char *role;

		role = g_strdup_printf ("epiphany-window-%x", rand());
		gtk_window_set_role (window, role);
		g_free (role);
	}
}
Exemplo n.º 5
0
static void
impl_attach_window (EphyExtension *extension,
		    EphyWindow *window)
{
	EphySession *session = EPHY_SESSION (extension);
	GtkWidget *notebook;

	LOG ("impl_attach_window");

	session->priv->windows = g_list_append (session->priv->windows, window);
	ephy_session_save (session, SESSION_STATE);

	g_signal_connect (window, "focus-in-event",
			  G_CALLBACK (window_focus_in_event_cb), session);

	notebook = ephy_window_get_notebook (window);
	g_signal_connect (notebook, "page-added",
			  G_CALLBACK (notebook_page_added_cb), session);
	g_signal_connect (notebook, "page-removed",
			  G_CALLBACK (notebook_page_removed_cb), session);
	g_signal_connect (notebook, "page-reordered",
			  G_CALLBACK (notebook_page_reordered_cb), session);

	/* Set unique identifier as role, so that on restore, the WM can
	 * place the window on the right workspace
	 */

	if (gtk_window_get_role (GTK_WINDOW (window)) == NULL)
	{
		/* I guess rand() is unique enough, otherwise we could use
		 * time + pid or something
		 */
		char *role;

		role = g_strdup_printf ("epiphany-window-%x", rand());
		gtk_window_set_role (GTK_WINDOW (window), role);
		g_free (role);
	}
}
Exemplo n.º 6
0
static void
notebook_drag_data_received_cb (GtkWidget        *widget,
                                GdkDragContext   *context,
                                int               x,
                                int               y,
                                GtkSelectionData *selection_data,
                                guint             info,
                                guint             time,
                                EphyEmbed        *embed)
{
  EphyWindow *window;
  GtkWidget *notebook;
  GdkAtom target;
  const guchar *data;

  target = gtk_selection_data_get_target (selection_data);
  if (target == gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB"))
    return;

  g_signal_stop_emission_by_name (widget, "drag-data-received");

  if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN,
                              EPHY_PREFS_LOCKDOWN_ARBITRARY_URL))
    return;

  data = gtk_selection_data_get_data (selection_data);
  if (gtk_selection_data_get_length (selection_data) <= 0 || data == NULL)
    return;

  window = EPHY_WINDOW (gtk_widget_get_toplevel (widget));
  notebook = ephy_window_get_notebook (window);

  if (target == gdk_atom_intern (EPHY_DND_URL_TYPE, FALSE)) {
    char **split;

    /* URL_TYPE has format: url \n title */
    split = g_strsplit ((const gchar *)data, "\n", 2);
    if (split != NULL && split[0] != NULL && split[0][0] != '\0') {
      ephy_link_open (EPHY_LINK (notebook), split[0], embed,
                      embed ? 0 : EPHY_LINK_NEW_TAB);
    }
    g_strfreev (split);
  } else if (target == gdk_atom_intern (EPHY_DND_URI_LIST_TYPE, FALSE)) {
    char **uris;
    int i;

    uris = gtk_selection_data_get_uris (selection_data);
    if (uris == NULL)
      return;

    for (i = 0; i < INSANE_NUMBER_OF_URLS && uris[i] != NULL; i++) {
      embed = ephy_link_open (EPHY_LINK (notebook), uris[i], embed,
                              (embed && i == 0) ? 0 : EPHY_LINK_NEW_TAB);
    }

    g_strfreev (uris);
  } else {
    char *text;

    text = (char *)gtk_selection_data_get_text (selection_data);
    if (text != NULL) {
      char *address;

      address = ephy_embed_utils_normalize_or_autosearch_address (text);
      ephy_link_open (EPHY_LINK (notebook), address, embed,
                      embed ? 0 : EPHY_LINK_NEW_TAB);
      g_free (address);
      g_free (text);
    }
  }
}