示例#1
0
gboolean on_dir_tree_view_drag_motion ( GtkWidget *widget,
                                      GdkDragContext *drag_context,
                                      gint x,
                                      gint y,
                                      guint time,
                                      PtkFileBrowser* file_browser )  //MOD added
{
    GdkDragAction suggested_action;
    GdkAtom target;
    GtkTargetList* target_list;

    target_list = gtk_target_list_new( drag_targets, G_N_ELEMENTS(drag_targets) );
    target = gtk_drag_dest_find_target( widget, drag_context, target_list );
    gtk_target_list_unref( target_list );

    if (target == GDK_NONE)
        gdk_drag_status( drag_context, 0, time);
    else
    {
        // Need to set suggested_action because default handler assumes copy
        /* Only 'move' is available. The user force move action by pressing Shift key */
        if( (gdk_drag_context_get_actions ( drag_context ) & GDK_ACTION_ALL) == GDK_ACTION_MOVE )
            suggested_action = GDK_ACTION_MOVE;
        /* Only 'copy' is available. The user force copy action by pressing Ctrl key */
        else if( (gdk_drag_context_get_actions ( drag_context ) & GDK_ACTION_ALL) == GDK_ACTION_COPY )
            suggested_action = GDK_ACTION_COPY;
        /* Only 'link' is available. The user force link action by pressing Shift+Ctrl key */
        else if( (gdk_drag_context_get_actions ( drag_context ) & GDK_ACTION_ALL) == GDK_ACTION_LINK )
            suggested_action = GDK_ACTION_LINK;
        /* Several different actions are available. We have to figure out a good default action. */
        else
        {
            int drag_action = xset_get_int( "drag_action", "x" );
            if ( drag_action == 1 )
                suggested_action = GDK_ACTION_COPY;
            else if ( drag_action == 2 )
                suggested_action = GDK_ACTION_MOVE;
            else if ( drag_action == 3 )
                suggested_action = GDK_ACTION_LINK;
            else
            {
                // automatic
                file_browser->pending_drag_status_tree = 1;
                gtk_drag_get_data (widget, drag_context, target, time);
                suggested_action = gdk_drag_context_get_selected_action( drag_context );
            }
        }
#if GTK_CHECK_VERSION (3, 0, 0)
        /* hack to be able to call the default handler with the correct suggested_action */
        struct _GdkDragContext {
          GObject parent_instance;

          /*< private >*/
          GdkDragProtocol protocol;
#if GTK_CHECK_VERSION (3, 22, 0)
          /* 1.0.6 per Teklad: _GdkDragContext appears to change between
           * different versions of GTK3 which causes the crash. It appears they
           * added/removed some variables from that struct.
           * https://github.com/IgnorantGuru/spacefm/issues/670 */
          GdkDisplay *display;
#endif
          gboolean is_source;
          GdkWindow *source_window;
          GdkWindow *dest_window;

          GList *targets;
          GdkDragAction actions;
          GdkDragAction suggested_action;
          GdkDragAction action;

          guint32 start_time;

          GdkDevice *device;
#if GTK_CHECK_VERSION (3, 22, 0)
          /* 1.0.6 per Teklad: _GdkDragContext appears to change between
           * different versions of GTK3 which causes the crash. It appears they
           * added/removed some variables from that struct.
           * https://github.com/IgnorantGuru/spacefm/issues/670 */
          guint drop_done : 1; /* Whether gdk_drag_drop_done() was performed */
#endif
        };
        ((struct _GdkDragContext *)drag_context)->suggested_action = suggested_action;
#else
        drag_context->suggested_action = suggested_action; // needed for default handler
#endif
        gdk_drag_status( drag_context, suggested_action, gtk_get_current_event_time() );
    }
    return FALSE;
}
示例#2
0
/**
 * @see https://developers.facebook.com/docs/authentication/
 * @returs NULL if the user cancel the operation or a valid token
 */
static gchar *facebook_get_user_auth_token(dt_storage_facebook_gui_data_t *ui)
{
  ///////////// open the authentication url in a browser
  GError *error = NULL;
  gtk_show_uri(gdk_screen_get_default(),
               FB_WS_BASE_URL"dialog/oauth?"
               "client_id=" FB_API_KEY
               "&redirect_uri="FB_WS_BASE_URL"connect/login_success.html"
               "&scope=user_photos,publish_stream"
               "&response_type=token", gtk_get_current_event_time(), &error);

  ////////////// build & show the validation dialog
  gchar *text1 = _("step 1: a new window or tab of your browser should have been "
                   "loaded. you have to login into your facebook account there "
                   "and authorize darktable to upload photos before continuing.");
  gchar *text2 = _("step 2: paste your browser URL and click the OK button once "
                   "you are done.");

  GtkWidget *window = dt_ui_main_window(darktable.gui->ui);
  GtkDialog *fb_auth_dialog = GTK_DIALOG(gtk_message_dialog_new (GTK_WINDOW (window),
                                         GTK_DIALOG_DESTROY_WITH_PARENT,
                                         GTK_MESSAGE_QUESTION,
                                         GTK_BUTTONS_OK_CANCEL,
                                         _("facebook authentication")));
  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (fb_auth_dialog),
      "%s\n\n%s", text1, text2);

  GtkWidget *entry = gtk_entry_new();
  GtkWidget *hbox = gtk_hbox_new(FALSE, 5);
  gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(gtk_label_new(_("URL:"))), FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entry), TRUE, TRUE, 0);

  GtkWidget *fbauthdialog_vbox = gtk_message_dialog_get_message_area(GTK_MESSAGE_DIALOG(fb_auth_dialog));
  gtk_box_pack_end(GTK_BOX(fbauthdialog_vbox), hbox, TRUE, TRUE, 0);

  gtk_widget_show_all(GTK_WIDGET(fb_auth_dialog));

  ////////////// wait for the user to enter the validation URL
  gint result;
  gchar *token = NULL;
  const char *replyurl;
  while (TRUE)
  {
    result = gtk_dialog_run (GTK_DIALOG (fb_auth_dialog));
    if (result == GTK_RESPONSE_CANCEL)
      break;
    replyurl = gtk_entry_get_text(GTK_ENTRY(entry));
    if (replyurl == NULL || g_strcmp0(replyurl, "") == 0)
    {
      gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(fb_auth_dialog),
          "%s\n\n%s\n\n<span foreground=\"" MSGCOLOR_RED "\" ><small>%s</small></span>",
          text1, text2, _("please enter the validation URL"));
      continue;
    }
    token = fb_extract_token_from_url(replyurl);
    if (token != NULL)//we have a valid token
      break;
    else
      gtk_message_dialog_format_secondary_markup(
        GTK_MESSAGE_DIALOG(fb_auth_dialog),
        "%s\n\n%s%s\n\n<span foreground=\"" MSGCOLOR_RED "\"><small>%s</small></span>",
        text1, text2,
        _("the given URL is not valid, it should look like: "),
        FB_WS_BASE_URL"connect/login_success.html?...");
  }
  gtk_widget_destroy(GTK_WIDGET(fb_auth_dialog));

  return token;
}
示例#3
0
static _flickr_api_context_t *_flickr_api_authenticate(dt_storage_flickr_gui_data_t *ui)
{
  char *perms = NULL, *frob;
  gchar *token;
  char *flickr_user_token = NULL;
  gint result;
  _flickr_api_context_t *ctx = (_flickr_api_context_t *)g_malloc0(sizeof(_flickr_api_context_t));

  flickcurl_init ();
  ctx->fc = flickcurl_new ();
  flickcurl_set_api_key (ctx->fc, API_KEY);
  flickcurl_set_shared_secret (ctx->fc, SHARED_SECRET);
  flickcurl_set_error_handler(ctx->fc, _flickr_api_error_handler, ctx);

  if (!ui->user_token)
  {
    // Retrieve stored auth_key
    // TODO: We should be able to store token for different users
    GHashTable* table = dt_pwstorage_get("flickr");
    gchar * _username = g_strdup( g_hash_table_lookup(table, "username"));
    gchar *_user_token = g_strdup( g_hash_table_lookup(table, "token"));
    g_hash_table_destroy(table);

    if (_username)
    {
      if (!strcmp(_username,gtk_entry_get_text(ui->entry1)))
      {
        flickr_user_token = g_strdup(_user_token);
        perms = flickcurl_auth_checkToken(ctx->fc, flickr_user_token);
      }
      g_free (_username);
    }
    if (_user_token)
      g_free (_user_token);
  }
  else
  {
    flickr_user_token = ui->user_token;
    perms = flickcurl_auth_checkToken(ctx->fc, ui->user_token);
  }


  if (perms)
  {
    ui->user_token = flickr_user_token;
    flickcurl_set_auth_token(ctx->fc, flickr_user_token);
    return ctx;

  }
  else if (!ctx->error_occured)
  {
    frob = flickcurl_auth_getFrob(ctx->fc);
    GError *error = NULL;
    char *sign = g_strdup_printf ("%sapi_key%sfrob%spermswrite", SHARED_SECRET, API_KEY, frob);
    char *sign_md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, sign, strlen (sign));
    gchar auth_url[250];
    snprintf(auth_url, sizeof(auth_url), "https://flickr.com/services/auth/?api_key=%s&perms=write&frob=%s&api_sig=%s", API_KEY, frob, sign_md5);

    if(!gtk_show_uri (gdk_screen_get_default(), auth_url, gtk_get_current_event_time (), &error))
    {
      fprintf(stderr, "[flickr] error opening browser: %s\n", error->message);
      g_error_free(error);
    }

    g_free(sign);
    g_free(sign_md5);

    // Hold here to let the user interact
    // Show a dialog.
    gchar *text1, *text2;
    text1 = g_strdup(_("step 1: a new window or tab of your browser should have been loaded. you have to login into your flickr account there and authorize darktable to upload photos before continuing."));
    text2 = g_strdup(_("step 2: click the OK button once you are done."));

    GtkWidget *window = dt_ui_main_window(darktable.gui->ui);
    GtkWidget *flickr_auth_dialog = gtk_message_dialog_new (GTK_WINDOW (window),
                                    GTK_DIALOG_DESTROY_WITH_PARENT,
                                    GTK_MESSAGE_INFO,
                                    GTK_BUTTONS_OK_CANCEL,
                                    _("flickr authentication"));
    gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (flickr_auth_dialog),
        "%s\n\n%s", text1, text2);

    result = gtk_dialog_run (GTK_DIALOG (flickr_auth_dialog));

    gtk_widget_destroy(flickr_auth_dialog);

    g_free (text1);
    g_free (text2);

    switch (result)
    {
      case GTK_RESPONSE_OK:
        token = flickcurl_auth_getToken(ctx->fc, frob);
        g_free(frob);
        // TODO: Handle timeouts errors
        if (token)
        {
          flickr_user_token = g_strdup (token);
        }
        else
        {
          g_free(token);
          _flickr_api_free(ctx);
          return NULL;
        }
        ui->user_token = g_strdup(flickr_user_token);
        flickcurl_set_auth_token(ctx->fc, flickr_user_token);

        /* Add creds to pwstorage */
        GHashTable *table = g_hash_table_new(g_str_hash, g_str_equal);
        gchar* username = g_strdup(gtk_entry_get_text(ui->entry1));

        g_hash_table_insert(table, "username", username);
        g_hash_table_insert(table, "token", flickr_user_token);

        if( !dt_pwstorage_set("flickr", table) )
        {
          dt_print(DT_DEBUG_PWSTORAGE,"[flickr] cannot store username/token\n");
        }

        g_free(flickr_user_token);
        g_hash_table_destroy(table);

        return ctx;
        break;

      default:
        dt_print(DT_DEBUG_PWSTORAGE,"[flickr] user cancelled the login process\n");
        return NULL;
    }
  }

  free(perms);

  return NULL;
}
示例#4
0
gboolean linphone_gtk_call_log_popup_contact(GtkWidget *list, GdkEventButton *event){
	GtkWidget *m=linphone_gtk_create_call_log_menu(list);
	gtk_menu_popup (GTK_MENU (m), NULL, NULL, NULL, NULL,
                  event ? event->button : 0, event ? event->time : gtk_get_current_event_time());
	return TRUE;
}
void PopupMenuGtk::show(const IntRect& rect, FrameView* view, int index)
{
    ASSERT(client());

    if (!m_popup) {
        m_popup = GTK_MENU(gtk_menu_new());
        g_signal_connect(m_popup.get(), "unmap", G_CALLBACK(menuUnmapped), this);
    } else
        gtk_container_foreach(GTK_CONTAINER(m_popup.get()), reinterpret_cast<GtkCallback>(menuRemoveItem), this);

    int x, y;
    gdk_window_get_origin(gtk_widget_get_window(GTK_WIDGET(view->hostWindow()->platformPageClient())), &x, &y);
    m_menuPosition = view->contentsToWindow(rect.location());
    m_menuPosition = IntPoint(m_menuPosition.x() + x, m_menuPosition.y() + y + rect.height());
    m_indexMap.clear();

    const int size = client()->listSize();
    for (int i = 0; i < size; ++i) {
        GtkWidget* item;
        if (client()->itemIsSeparator(i))
            item = gtk_separator_menu_item_new();
        else
            item = gtk_menu_item_new_with_label(client()->itemText(i).utf8().data());

        m_indexMap.add(item, i);
        g_signal_connect(item, "activate", G_CALLBACK(menuItemActivated), this);

        // FIXME: Apply the PopupMenuStyle from client()->itemStyle(i)
        gtk_widget_set_sensitive(item, client()->itemIsEnabled(i));
        gtk_menu_shell_append(GTK_MENU_SHELL(m_popup.get()), item);
        gtk_widget_show(item);
    }

    gtk_menu_set_active(m_popup.get(), index);


    // The size calls are directly copied from gtkcombobox.c which is LGPL
    GtkRequisition requisition;
    gtk_widget_set_size_request(GTK_WIDGET(m_popup.get()), -1, -1);
    gtk_widget_size_request(GTK_WIDGET(m_popup.get()), &requisition);
    gtk_widget_set_size_request(GTK_WIDGET(m_popup.get()), std::max(rect.width(), requisition.width), -1);

    GList* children = gtk_container_get_children(GTK_CONTAINER(m_popup.get()));
    GList* p = children;
    if (size)
        for (int i = 0; i < size; i++) {
            if (i > index)
              break;

            GtkWidget* item = reinterpret_cast<GtkWidget*>(p->data);
            GtkRequisition itemRequisition;
            gtk_widget_get_child_requisition(item, &itemRequisition);
            m_menuPosition.setY(m_menuPosition.y() - itemRequisition.height);

            p = g_list_next(p);
        } else
            // Center vertically the empty popup in the combo box area
            m_menuPosition.setY(m_menuPosition.y() - rect.height() / 2);

    g_list_free(children);
    gtk_menu_popup(m_popup.get(), 0, 0, reinterpret_cast<GtkMenuPositionFunc>(menuPositionFunction), this, 0, gtk_get_current_event_time());
}
示例#6
0
static gboolean on_modules_list_button_release(GtkWidget *widget,
					       GdkEventButton *event,
					       gpointer user_data)
{
	GtkTreeSelection *selection;
	GtkTreeIter selected;
	GtkTreeModel *model;
	gchar *mod = NULL;
	gchar *caption = NULL;

	selection =
	    gtk_tree_view_get_selection(GTK_TREE_VIEW(sidebar.module_list));

	if (!gtk_tree_selection_get_selected(selection, &model, &selected))
		return FALSE;

	gtk_tree_model_get(GTK_TREE_MODEL(model), &selected, 2, &caption,
			   3, &mod, -1);

	//uncomment the following two lines if you want to see how it looks without
	//triangls or plus symbols
	//gtk_tree_view_set_show_expanders(sidebar.module_list, FALSE);
	//gtk_tree_view_set_level_indentation(sidebar.module_list, 12);
	GtkTreePath *path = gtk_tree_model_get_path(model, &selected);
	if (gtk_tree_view_row_expanded(GTK_TREE_VIEW(sidebar.module_list), path))
		gtk_tree_view_collapse_row(GTK_TREE_VIEW(sidebar.module_list), path);
	else
		gtk_tree_view_expand_row(GTK_TREE_VIEW(sidebar.module_list), path,
					 FALSE);
	gtk_tree_path_free(path);

	switch (event->button) {
	case 1:
		main_mod_treeview_button_one(model, selected);
		break;

	case 2:
		if (mod && (g_utf8_collate(mod, _("Parallel View"))) && (g_utf8_collate(mod, _("Standard View"))))
			gui_open_module_in_new_tab(mod);
		break;

	case 3:
		if (mod && (g_utf8_collate(mod, _("Parallel View"))) && (g_utf8_collate(mod, _("Standard View"))) //) {
		    && (main_get_mod_type(mod) != PRAYERLIST_TYPE)) {
			buf_module = mod;
			create_menu_modules();
			/*gtk_menu_popup(GTK_MENU(sidebar.menu_modules),
			   NULL, NULL, NULL, NULL,
			   0, gtk_get_current_event_time()); */
			g_free(caption);
			return FALSE;
		}
		if (caption &&
		    (!g_utf8_collate(caption, _("Prayer List/Journal")))) {
			gui_menu_prayerlist_popup(NULL, NULL);
			g_free(mod);
			return FALSE;
		}
		if (mod && (main_get_mod_type(mod) == PRAYERLIST_TYPE)) {
			buf_module = mod;
			gtk_menu_popup(GTK_MENU(sidebar.menu_prayerlist_mod), NULL,
				       NULL, NULL, NULL, 0,
				       gtk_get_current_event_time());
			g_free(caption);
			return FALSE;
		}

		break;
	}
	g_free(caption);
	g_free(mod);
	return FALSE;
}
示例#7
0
void on_trayicon_activate (GtkStatusIcon *status_icon,
			   gpointer       user_data)
{
  GromitData *data = (GromitData *) user_data;
  if(data->debug)
    g_printerr("DEBUG: trayicon activated\n");

  /* create the menu */
  GtkWidget *menu = gtk_menu_new ();
  
  /* Create the menu items */
  GtkWidget* toggle_paint_item = gtk_image_menu_item_new_with_label ("Toggle Painting");
  GtkWidget* clear_item = gtk_image_menu_item_new_with_label ("Clear Screen");
  GtkWidget* toggle_vis_item = gtk_image_menu_item_new_with_label ("Toggle Visibility");
  GtkWidget* thicker_lines_item = gtk_image_menu_item_new_with_label ("Thicker Lines");
  GtkWidget* thinner_lines_item = gtk_image_menu_item_new_with_label ("Thinner Lines");
  GtkWidget* opacity_bigger_item = gtk_image_menu_item_new_with_label ("Bigger Opacity");
  GtkWidget* opacity_lesser_item = gtk_image_menu_item_new_with_label ("Lesser Opacity");
  GtkWidget* undo_item = gtk_image_menu_item_new_with_label ("Undo");
  GtkWidget* redo_item = gtk_image_menu_item_new_with_label ("Redo");


  /* Add them to the menu */
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), toggle_paint_item);
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), clear_item);
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), toggle_vis_item);
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), thicker_lines_item);
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), thinner_lines_item);
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), opacity_bigger_item);
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), opacity_lesser_item);
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), undo_item);
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), redo_item);


  /* Attach the callback functions to the respective activate signal */
  // TODO add per-device submenu for toggle_paint_item 
  g_signal_connect(G_OBJECT (clear_item), "activate",
		   G_CALLBACK (on_clear),
		   data);
  g_signal_connect(G_OBJECT (toggle_vis_item), "activate",
		   G_CALLBACK (on_toggle_vis),
		   data);

  g_signal_connect(G_OBJECT (thicker_lines_item), "activate",
		   G_CALLBACK (on_thicker_lines),
		   data);
  g_signal_connect(G_OBJECT (thinner_lines_item), "activate",
		   G_CALLBACK (on_thinner_lines),
		   data);
  g_signal_connect(G_OBJECT (opacity_bigger_item), "activate",
		   G_CALLBACK (on_opacity_bigger),
		   data);
  g_signal_connect(G_OBJECT (opacity_lesser_item), "activate",
		   G_CALLBACK (on_opacity_lesser),
		   data);

  g_signal_connect(G_OBJECT (undo_item), "activate",
		   G_CALLBACK (on_undo),
		   data);
  g_signal_connect(G_OBJECT (redo_item), "activate",
		   G_CALLBACK (on_redo),
		   data);
 

  /* We do need to show menu items */
  gtk_widget_show (toggle_paint_item);
  gtk_widget_show (clear_item);
  gtk_widget_show (toggle_vis_item);
  gtk_widget_show (thicker_lines_item);
  gtk_widget_show (thinner_lines_item);
  gtk_widget_show (opacity_bigger_item);
  gtk_widget_show (opacity_lesser_item);
  gtk_widget_show (undo_item);
  gtk_widget_show (redo_item);
 

  /* show menu */
  gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
                  0, gtk_get_current_event_time());
}
示例#8
0
void PopupMenu::show(const IntRect& rect, FrameView* view, int index)
{
    ASSERT(client());

    if (!m_popup) {
        m_popup = GTK_MENU(gtk_menu_new());
        g_object_ref_sink(G_OBJECT(m_popup));
        g_signal_connect(m_popup, "unmap", G_CALLBACK(menuUnmapped), this);
// <lab126>
        g_signal_emit_by_name(view->hostWindow()->platformWindow(), "drop-down-menu", m_popup);
// </lab126>
    } else
        gtk_container_foreach(GTK_CONTAINER(m_popup), reinterpret_cast<GtkCallback>(menuRemoveItem), this);


    int x, y, wHeight;
    gdk_window_get_origin(GTK_WIDGET(view->hostWindow()->platformWindow())->window, &x, &y);
    gdk_window_get_geometry(GTK_WIDGET(view->hostWindow()->platformWindow())->window, NULL, NULL, NULL, &wHeight, NULL);
    m_menuPosition = view->contentsToWindow(rect.location());
  //  m_menuPosition = IntPoint(m_menuPosition.x() + x, m_menuPosition.y() + y + rect.height());
    m_indexMap.clear();

    const int size = client()->listSize();
    for (int i = 0; i < size; ++i) {
        GtkWidget* item;
        if (client()->itemIsSeparator(i)) {
            item = gtk_separator_menu_item_new();
        } else {
            item = gtk_menu_item_new_with_label(client()->itemText(i).utf8().data());
        }

        m_indexMap.add(item, i);
        g_signal_connect(item, "activate", G_CALLBACK(menuItemActivated), this);

        // FIXME: Apply the PopupMenuStyle from client()->itemStyle(i)
        gtk_widget_set_sensitive(item, client()->itemIsEnabled(i));
        gtk_menu_shell_append(GTK_MENU_SHELL(m_popup), item);
        gtk_widget_show(item);
    }

    gtk_menu_set_active(m_popup, index);


    // The size calls are directly copied from gtkcombobox.c which is LGPL
    GtkRequisition requisition;
    gtk_widget_set_size_request(GTK_WIDGET(m_popup), -1, -1);
    gtk_widget_size_request(GTK_WIDGET(m_popup), &requisition);
    gtk_widget_set_size_request(GTK_WIDGET(m_popup), MAX(rect.width(), requisition.width), -1);
    // <lab126>: Position the menu items such that there are no empty spaces and also make sure that 
    // the previously selected item stays visible. 
    if ( requisition.height > wHeight) {
        GList* children = GTK_MENU_SHELL(m_popup)->children;
        GtkWidget* item = reinterpret_cast<GtkWidget*>(children->data);
        GtkRequisition itemRequisition;
        gtk_widget_get_child_requisition(item, &itemRequisition);
        int itemHeight = itemRequisition.height;
        // Move the items up until the indexed item fits in to the visible part of the window
        // Count out the two scoll items from the window height
        if ( ( itemHeight * ( index + 1 ) ) >  ( wHeight -  (2 * itemHeight ) ) ) {
            int itemsToRemove = ( ( (itemHeight * index  ) -   ( wHeight -  (2 * itemHeight ) )  ) / itemHeight );
            if (size)
                m_menuPosition.setY(y - ( ( itemsToRemove + 1 ) * itemHeight ) );

        } else
               // Place the first item at the top of window
               m_menuPosition.setY(y);

    }

    // </lab126> 
    gtk_menu_popup(m_popup, NULL, NULL, reinterpret_cast<GtkMenuPositionFunc>(menuPositionFunction), this, 0, gtk_get_current_event_time());
}
示例#9
0
static void 
awn_CPUicon_show_context_menu(AwnCPUicon *self)
{
  AwnCPUiconPrivate *priv;
  AwnApplet         *applet;
  GtkWidget         *item;
  GtkWidget         *submenu;
  gboolean          render_bg;

  g_object_get (self,
                "render-bg", &render_bg,
                NULL);
  
  priv = AWN_CPUICON_GET_PRIVATE (self);
  if (priv->context_menu)
  {
    gtk_widget_destroy (priv->context_menu);
  }
  g_object_get (self,
                "applet",&applet,
                NULL);
  
  priv->context_menu = awn_applet_create_default_menu(applet);
  item = gtk_menu_item_new_with_label (_("Graph Type"));
  gtk_menu_shell_append(GTK_MENU_SHELL(priv->context_menu), item);
  
  submenu = gtk_menu_new ();
  gtk_menu_item_set_submenu (GTK_MENU_ITEM(item),submenu);
  
  /* Translators: refers to a graph type */
  item = gtk_menu_item_new_with_label (_("Area"));
  gtk_menu_shell_append(GTK_MENU_SHELL(submenu), item);
  g_signal_connect_swapped (item, "activate", G_CALLBACK(change_to_area), self);
  item = gtk_menu_item_new_with_label (_("Circle"));
  gtk_menu_shell_append(GTK_MENU_SHELL(submenu), item);
  g_signal_connect_swapped (item, "activate", G_CALLBACK(change_to_circle), self);  
  item = gtk_menu_item_new_with_label (_("Bars"));
  gtk_menu_shell_append(GTK_MENU_SHELL(submenu), item);
  g_signal_connect_swapped (item, "activate", G_CALLBACK(change_to_bars), self);  
  item = gtk_menu_item_new_with_label (_("Default"));
  gtk_menu_shell_append(GTK_MENU_SHELL(submenu), item);
  g_signal_connect_swapped (item, "activate", G_CALLBACK(change_to_default), self);  

/*  item = gtk_menu_item_new_with_label ("Add Icon");
  gtk_menu_shell_append(GTK_MENU_SHELL(priv->context_menu), item);
  submenu = gtk_menu_new ();
  gtk_menu_item_set_submenu (GTK_MENU_ITEM(item),submenu);
  item = gtk_menu_item_new_with_label ("CPU");
  gtk_menu_shell_append(GTK_MENU_SHELL(submenu), item);
*/
/*  item = gtk_menu_item_new_with_label ("Remove Icon");
  gtk_menu_shell_append(GTK_MENU_SHELL(priv->context_menu), item);  
*/
  item = gtk_check_menu_item_new_with_label (_("Render Background"));
  gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM (item),render_bg);  
  gtk_menu_shell_append(GTK_MENU_SHELL(priv->context_menu), item);
  g_signal_connect_swapped (item, "activate", G_CALLBACK(change_render_bg), self);  

  item = awn_applet_create_about_item_simple (applet,
                                              "Copyright 2009 Rodney Cryderman <*****@*****.**>\n",
                                              AWN_APPLET_LICENSE_GPLV2,
                                              VERSION);
  gtk_menu_shell_append(GTK_MENU_SHELL(priv->context_menu), item);
  
  gtk_widget_show_all (priv->context_menu);
  awn_utils_show_menu_images (GTK_MENU(priv->context_menu));
  awn_applet_popup_gtk_menu (applet, priv->context_menu, 0, gtk_get_current_event_time());
}
示例#10
0
文件: randr.c 项目: pzanoni/tray
static void popup()
{
    gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3,
                   gtk_get_current_event_time());
}
示例#11
0
gint64
empathy_get_current_action_time (void)
{
  return (tp_user_action_time_from_x11 (gtk_get_current_event_time ()));
}
static void
thunar_location_entry_button_clicked (GtkWidget           *button,
                                      ThunarLocationEntry *location_entry)
{
  ThunarShortcutsModel *model;
  ThunarIconFactory    *icon_factory;
  ThunarVfsVolume      *volume;
  GtkIconTheme         *icon_theme;
  const gchar          *icon_name;
  GtkTreeIter           iter;
  ThunarFile           *file;
  GtkWidget            *image;
  GtkWidget            *item;
  GtkWidget            *menu;
  GdkPixbuf            *icon;
  gint                  icon_size;
  gint                  width;

  _thunar_return_if_fail (THUNAR_IS_LOCATION_ENTRY (location_entry));
  _thunar_return_if_fail (GTK_IS_TOGGLE_BUTTON (button));

  /* allocate a new menu */
  menu = gtk_menu_new ();

  /* determine the icon theme and factory */
  icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (button));
  icon_factory = thunar_icon_factory_get_for_icon_theme (icon_theme);

  /* determine the icon size for menus */
  gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &icon_size, &icon_size);

  /* load the menu items from the shortcuts model */
  model = thunar_shortcuts_model_get_default ();
  if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter))
    {
      do
        {
          /* determine the file and volume for the item */
          gtk_tree_model_get (GTK_TREE_MODEL (model), &iter,
                              THUNAR_SHORTCUTS_MODEL_COLUMN_FILE, &file,
                              THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME, &volume,
                              -1);

          /* check if we have a separator here */
          if (G_UNLIKELY (file == NULL && volume == NULL))
            {
              /* generate a separator the menu */
              item = gtk_separator_menu_item_new ();
            }
          else if (G_UNLIKELY (volume != NULL))
            {
              /* generate an image menu item for the volume */
              item = gtk_image_menu_item_new_with_label (thunar_vfs_volume_get_name (volume));

              /* load the icon for the volume */
              icon_name = thunar_vfs_volume_lookup_icon_name (volume, icon_theme);
              icon = thunar_icon_factory_load_icon (icon_factory, icon_name, icon_size, NULL, FALSE);
              if (G_LIKELY (icon != NULL))
                {
                  /* generate an image for the menu item */
                  image = gtk_image_new_from_pixbuf (icon);
                  gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
                  g_object_unref (G_OBJECT (icon));
                  gtk_widget_show (image);
                }
            }
          else
            {
              /* generate an image menu item for the file */
              item = gtk_image_menu_item_new_with_label (thunar_file_get_display_name (file));

              /* load the icon for the file and generate the image for the menu item */
              icon = thunar_icon_factory_load_file_icon (icon_factory, file, THUNAR_FILE_ICON_STATE_DEFAULT, icon_size);
              image = gtk_image_new_from_pixbuf (icon);
              gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
              g_object_unref (G_OBJECT (icon));
              gtk_widget_show (image);
            }

          /* connect the file and volume to the item */
          g_object_set_data_full (G_OBJECT (item), I_("thunar-vfs-volume"), volume, g_object_unref);
          g_object_set_data_full (G_OBJECT (item), I_("thunar-file"), file, g_object_unref);

          /* append the new item to the menu */
          g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (thunar_location_entry_item_activated), location_entry);
          gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
          gtk_widget_show (item);
        }
      while (gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter));
    }

  /* make sure the menu has atleast the same width as the location entry */
  width = GTK_WIDGET (location_entry)->allocation.width - 2 * gtk_container_get_border_width (GTK_CONTAINER (location_entry));
  if (G_LIKELY (menu->allocation.width < width))
    gtk_widget_set_size_request (menu, width, -1);

  /* select the first visible or selectable item in the menu */
  gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), TRUE);

  /* enable the button, making sure that we do not recurse on the "clicked" signal by temporarily blocking the handler */
  g_signal_handlers_block_by_func (G_OBJECT (button), G_CALLBACK (thunar_location_entry_button_clicked), location_entry);
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
  g_signal_handlers_unblock_by_func (G_OBJECT (button), G_CALLBACK (thunar_location_entry_button_clicked), location_entry);

  /* run the menu, taking ownership over the menu object */
  thunar_gtk_menu_run (GTK_MENU (menu), button, menu_position, location_entry, 1, gtk_get_current_event_time ());

  /* disable the button, making sure that we do not recurse on the "clicked" signal by temporarily blocking the handler */
  g_signal_handlers_block_by_func (G_OBJECT (button), G_CALLBACK (thunar_location_entry_button_clicked), location_entry);
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
  g_signal_handlers_unblock_by_func (G_OBJECT (button), G_CALLBACK (thunar_location_entry_button_clicked), location_entry);

  /* clean up */
  g_object_unref (G_OBJECT (icon_factory));
  g_object_unref (G_OBJECT (model));
}
示例#13
0
static void
activate_window(Display *display, Window window)
{
    Window toplevel = window;
    Atom window_state_atom = gdk_x11_get_xatom_by_name("WM_STATE");
    Atom active_window_atom = gdk_x11_get_xatom_by_name("_NET_ACTIVE_WINDOW");
    Window root;
    XEvent xev;
    
    /* The window_id we have is the window ID of a child window. So, we first
     * need to walk up the window hierarachy until we find the WM_STATE window,
     * then activate that window. Lots of X roundtrips here, but we only do
     * this on a user click as an alternative to launching a new firefox 
     * process, so it doesn't really matter.
     */
    gdk_error_trap_push();

    while (TRUE) {
        Window parent;
        Window *children;
        guint n_children;
        
        Atom type;
        int format;
        gulong n_items;
        gulong bytes_after;
        guchar *data;

        if (!XQueryTree(display, toplevel, &root, &parent, &children, &n_children)) {
            g_debug("XQueryTree failed\n");
            goto out;
        }

        XFree(children);

        if (root == parent) /* No window manager or non-reparenting window manager */
            break;
        
        if (XGetWindowProperty(display, toplevel, window_state_atom,
                               0, G_MAXLONG, False, AnyPropertyType,
                               &type, &format, &n_items, &bytes_after, &data) != Success) {
            g_debug("XGetWindowProperty failed\n");
            goto out;
        }
        
        if (type != None) { /* Found the real client toplevel */
            XFree(data);
            break;
        }

        toplevel = parent;
    }

    xev.xclient.type = ClientMessage;
    xev.xclient.window = toplevel;
    xev.xclient.message_type = active_window_atom;
    xev.xclient.format = 32;
    xev.xclient.data.l[0] = 2; /* We're sort of like a pager ... we're activating a window
                                * from a different app as a response to direct user action
                                */
    xev.xclient.data.l[1] = gtk_get_current_event_time();
    xev.xclient.data.l[2] = None; /* We don't really have an active toplevel */
    xev.xclient.data.l[3] = 0;
    xev.xclient.data.l[4] = 0;

    XSendEvent(display, root, False, SubstructureNotifyMask | SubstructureRedirectMask, &xev);

 out:
    gdk_error_trap_pop();
}
static void
notebook_popup_menu_show (CajaNavigationWindowPane *pane,
                          GdkEventButton *event)
{
    GtkWidget *popup;
    GtkWidget *item;
    GtkWidget *image;
    int button, event_time;
    gboolean can_move_left, can_move_right;
    CajaNotebook *notebook;

    notebook = CAJA_NOTEBOOK (pane->notebook);

    can_move_left = caja_notebook_can_reorder_current_child_relative (notebook, -1);
    can_move_right = caja_notebook_can_reorder_current_child_relative (notebook, 1);

    popup = gtk_menu_new();

    item = gtk_menu_item_new_with_mnemonic (_("_New Tab"));
    g_signal_connect (item, "activate",
    		  G_CALLBACK (notebook_popup_menu_new_tab_cb),
    		  pane);
    gtk_menu_shell_append (GTK_MENU_SHELL (popup),
    		       item);

    gtk_menu_shell_append (GTK_MENU_SHELL (popup),
    		       gtk_separator_menu_item_new ());

    item = gtk_menu_item_new_with_mnemonic (_("Move Tab _Left"));
    g_signal_connect (item, "activate",
                      G_CALLBACK (notebook_popup_menu_move_left_cb),
                      pane);
    gtk_menu_shell_append (GTK_MENU_SHELL (popup),
                           item);
    gtk_widget_set_sensitive (item, can_move_left);

    item = gtk_menu_item_new_with_mnemonic (_("Move Tab _Right"));
    g_signal_connect (item, "activate",
                      G_CALLBACK (notebook_popup_menu_move_right_cb),
                      pane);
    gtk_menu_shell_append (GTK_MENU_SHELL (popup),
                           item);
    gtk_widget_set_sensitive (item, can_move_right);

    gtk_menu_shell_append (GTK_MENU_SHELL (popup),
                           gtk_separator_menu_item_new ());

    item = gtk_image_menu_item_new_with_mnemonic (_("_Close Tab"));
    image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
    gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
    g_signal_connect (item, "activate",
                      G_CALLBACK (notebook_popup_menu_close_cb), pane);
    gtk_menu_shell_append (GTK_MENU_SHELL (popup),
                           item);

    gtk_widget_show_all (popup);

    if (event)
    {
        button = event->button;
        event_time = event->time;
    }
    else
    {
        button = 0;
        event_time = gtk_get_current_event_time ();
    }

    /* TODO is this correct? */
    gtk_menu_attach_to_widget (GTK_MENU (popup),
                               pane->notebook,
                               NULL);

    gtk_menu_popup (GTK_MENU (popup), NULL, NULL, NULL, NULL,
                    button, event_time);
}
示例#15
0
static void sico_activated (GtkWidget *data)
{
	stashes_popup_menu = gtk_menu_new ();

	GtkWidget *mi = gtk_menu_item_new ();
	GtkWidget *w = gtk_label_new (NULL);
	gtk_label_set_markup (GTK_LABEL (w), _("<b>Encrypted folders:</b>"));
	gtk_container_add (GTK_CONTAINER (mi), w);
	gtk_widget_set_sensitive (mi, FALSE);
	gtk_menu_append (stashes_popup_menu, mi);

	int i = 0;
	std::vector<CryptPoint>::iterator it;
	// find out which ones are mounted
	for (it = cryptPoints.begin (); it != cryptPoints.end (); ++it, i++) {
		struct stat s;

		(*it).SetIsMounted (false);
		(*it).SetIsAvailable (false);

		if (stat ((*it).GetCryptDir (), &s) != -1) {
			if (S_ISDIR (s.st_mode)) (*it).SetIsAvailable (true);
		}

		// to get rid of festering mount points
		if (!config_keep_mountpoints) rmdir ((*it).GetMountDir ());

		if (is_mounted((*it).GetMountDir())) {
			if (S_ISDIR (s.st_mode)) (*it).SetIsMounted (true);
		}
	}
	
	i = 0;
	for (it = cryptPoints.begin (); it != cryptPoints.end (); ++it, i++) {
		mi = gtk_check_menu_item_new ();
		char buf[256];
		if ((*it).GetIsAvailable ()) {
			snprintf (buf, sizeof (buf), "%s", (*it).GetMountDir ());
		} else {
			snprintf (buf, sizeof (buf), "<span foreground=\"grey\">%s</span>", (*it).GetMountDir ());
		}
		GtkWidget *label = gtk_label_new (NULL);
		gtk_label_set_markup (GTK_LABEL (label), buf);
		gtk_container_add (GTK_CONTAINER (mi), label);
		gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), (*it).GetIsMounted ());
		//gtk_widget_set_sensitive (mi, (*it).GetIsAvailable ());
		gtk_menu_append (stashes_popup_menu, mi);
		g_signal_connect (G_OBJECT (mi), "toggled", G_CALLBACK (on_mount_check_item_toggled), GINT_TO_POINTER (i));
		g_signal_connect (G_OBJECT (mi), "button-release-event", G_CALLBACK (on_button_release), GINT_TO_POINTER (i));
	}

	mi = gtk_separator_menu_item_new ();
	gtk_menu_append (stashes_popup_menu, mi);

	mi = gtk_menu_item_new_with_label (_("Import EncFS folder"));
	g_signal_connect (G_OBJECT (mi), "activate", G_CALLBACK (on_import_stash_clicked), NULL);
	gtk_menu_append (stashes_popup_menu, mi);
	
	mi = gtk_menu_item_new_with_label (_("New encrypted folder"));
	g_signal_connect (G_OBJECT (mi), "activate", G_CALLBACK (on_create_new_stash_clicked), NULL);
	gtk_menu_append (stashes_popup_menu, mi);
	
	gtk_widget_show_all (stashes_popup_menu);

	gtk_menu_popup (GTK_MENU (stashes_popup_menu), NULL, NULL, gtk_status_icon_position_menu, sico,
			0, gtk_get_current_event_time ());
}
示例#16
0
static void
sql_favorite_clicked_cb (G_GNUC_UNUSED GtkButton *button, QueryConsolePage *tconsole)
{
	GtkWidget *menu, *mitem;
	TFavorites *tfav;

	if (tconsole->priv->favorites_menu)
		gtk_widget_destroy (tconsole->priv->favorites_menu);

	menu = gtk_menu_new ();
	tconsole->priv->favorites_menu = menu;
	mitem = gtk_menu_item_new_with_label (_("New favorite"));
	g_signal_connect (mitem, "activate",
			  G_CALLBACK (sql_favorite_new_mitem_cb), tconsole);
	gtk_widget_show (mitem);
	gtk_menu_shell_append (GTK_MENU_SHELL (menu), mitem);

	tfav = t_connection_get_favorites (tconsole->priv->tcnc);
	if (tconsole->priv->fav_id >= 0) {
		TFavoritesAttributes fav;
		if (t_favorites_get (tfav, tconsole->priv->fav_id, &fav, NULL)) {
			gchar *str;
			str = g_strdup_printf (_("Modify favorite '%s'"), fav.name);
			mitem = gtk_menu_item_new_with_label (str);
			g_free (str);
			g_signal_connect (mitem, "activate",
					  G_CALLBACK (sql_favorite_modify_mitem_cb), tconsole);
			g_object_set_data_full (G_OBJECT (mitem), "favname",
						g_strdup (fav.name), g_free);
			g_object_set_data (G_OBJECT (mitem), "favid",
					   GINT_TO_POINTER (tconsole->priv->fav_id));
			gtk_widget_show (mitem);
			gtk_menu_shell_append (GTK_MENU_SHELL (menu), mitem);
			t_favorites_reset_attributes (&fav);
		}
	}

	GSList *allfav;
	allfav = t_favorites_list (tfav, 0, T_FAVORITES_QUERIES, ORDER_KEY_QUERIES, NULL);
	if (allfav) {
		GtkWidget *submenu;
		GSList *list;

		mitem = gtk_menu_item_new_with_label (_("Modify a favorite"));
		gtk_widget_show (mitem);
		gtk_menu_shell_append (GTK_MENU_SHELL (menu), mitem);

		submenu = gtk_menu_new ();
		gtk_menu_item_set_submenu (GTK_MENU_ITEM (mitem), submenu);
		for (list = allfav; list; list = list->next) {
			TFavoritesAttributes *fav;
			fav = (TFavoritesAttributes*) list->data;
			if (fav->id == tconsole->priv->fav_id)
				continue;
			gchar *str;
			str = g_strdup_printf (_("Modify favorite '%s'"), fav->name);
			mitem = gtk_menu_item_new_with_label (str);
			g_free (str);
			g_signal_connect (mitem, "activate",
					  G_CALLBACK (sql_favorite_modify_mitem_cb), tconsole);
			g_object_set_data_full (G_OBJECT (mitem), "favname",
						g_strdup (fav->name), g_free);
			g_object_set_data (G_OBJECT (mitem), "favid",
					   GINT_TO_POINTER (fav->id));
			gtk_widget_show (mitem);
			gtk_menu_shell_append (GTK_MENU_SHELL (submenu), mitem);
		}
		t_favorites_free_list (allfav);
	}

	gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
			NULL, NULL, 0,
			gtk_get_current_event_time ());
}
示例#17
0
int
main (int argc, char **argv)
{
    char           *desktopfile;
    GOptionContext *context;
    GError         *error;

    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
    textdomain (GETTEXT_PACKAGE);

    /* We will register explicitly when we're ready -- see panel-session.c */
    egg_sm_client_set_mode (EGG_SM_CLIENT_MODE_DISABLED);

    g_set_prgname ("mate-panel");

    desktopfile = panel_g_lookup_in_applications_dirs ("mate-panel.desktop");
    if (desktopfile) {
        egg_set_desktop_file (desktopfile);
        g_free (desktopfile);
    }

    context = g_option_context_new ("");
    g_option_context_add_group (context,
                                egg_sm_client_get_option_group ());
    g_option_context_add_group (context, gtk_get_option_group (TRUE));
    g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);

    gtk_init (&argc, &argv);

    error = NULL;
    if (!g_option_context_parse (context, &argc, &argv, &error)) {
        g_printerr ("%s\n", error->message);
        g_error_free (error);
        g_option_context_free (context);

        return 1;
    }

    g_option_context_free (context);

    /* set the default layout */
    if (layout != NULL && layout[0] != 0)
    {
        GSettings *settings;
        settings = g_settings_new (PANEL_SCHEMA);
        g_settings_set_string (settings, PANEL_DEFAULT_LAYOUT, layout);
        g_object_unref (settings);
        g_message ("Panel layout set to '%s'", layout);
        /* exit, except if reset argument is given */
        if (!reset)
            return 0;
    }

    /* reset the configuration and exit. */
    if (reset == TRUE)
    {
        panel_reset();
        return 0;
    }

    /* open the run dialog and exit */
    if (run_dialog == TRUE)
    {
        panel_init_stock_icons_and_items ();
        panel_multiscreen_init ();
        panel_global_config_load ();
        panel_lockdown_init ();
        panel_profile_settings_load ();
        panel_run_dialog_present (gdk_screen_get_default (),
                                  gtk_get_current_event_time ());
        panel_run_dialog_quit_on_destroy ();
        gtk_main ();
        panel_lockdown_finalize ();
        panel_cleanup_do ();
        return 0;
    }

    if (!egg_get_desktop_file ()) {
        g_set_application_name (_("Panel"));
        gtk_window_set_default_icon_name (PANEL_ICON_PANEL);
    }

    if (!panel_shell_register (replace)) {
        panel_cleanup_do ();
        return -1;
    }

    panel_action_protocol_init ();
    panel_multiscreen_init ();
    panel_init_stock_icons_and_items ();

    panel_global_config_load ();
    panel_lockdown_init ();
    panel_profile_load ();

    /*add forbidden lists to ALL panels*/
    g_slist_foreach (panels,
                     (GFunc)panel_widget_add_forbidden,
                     NULL);

    xstuff_init ();

    /* Flush to make sure our struts are seen by everyone starting
     * immediate after (eg, the caja desktop). */
    gdk_flush ();

    /* Do this at the end, to be sure that we're really ready when
     * connecting to the session manager */
    panel_session_init ();

    gtk_main ();

    panel_lockdown_finalize ();

    panel_cleanup_do ();

    return 0;
}
示例#18
0
gboolean vfs_exec_on_screen( GdkScreen* screen,
                             const char* work_dir,
                             char** argv, char** envp,
                             const char* disp_name,
                             GSpawnFlags flags,
                             GError **err )
{
#ifdef HAVE_SN
    SnLauncherContext * ctx = NULL;
    SnDisplay* display;
#endif
    gboolean ret;
    GSpawnChildSetupFunc setup_func = NULL;
    extern char **environ;
    char** new_env = envp;
    int i, n_env = 0;
    char* display_name;
    int display_index = -1, startup_id_index = -1;

    if ( ! envp )
        envp = environ;

    n_env = g_strv_length(envp);

    new_env = g_new0( char*, n_env + 4 );
    for ( i = 0; i < n_env; ++i )
    {
        /* g_debug( "old envp[%d] = \"%s\"" , i, envp[i]); */
        if ( 0 == strncmp( envp[ i ], "DISPLAY=", 8 ) )
            display_index = i;
        else
        {
            if ( 0 == strncmp( envp[ i ], "DESKTOP_STARTUP_ID=", 19 ) )
                startup_id_index = i;
            new_env[i] = g_strdup( envp[ i ] );
        }
    }

#ifdef HAVE_SN
    display = sn_display_new ( GDK_SCREEN_XDISPLAY ( screen ),
                               ( SnDisplayErrorTrapPush ) gdk_error_trap_push,
                               ( SnDisplayErrorTrapPush ) gdk_error_trap_pop );
    if ( G_LIKELY ( display ) )
    {
        if ( !disp_name )
            disp_name = argv[ 0 ];

        ctx = sn_launcher_context_new( display, gdk_screen_get_number( screen ) );

        sn_launcher_context_set_description( ctx, disp_name );
        sn_launcher_context_set_name( ctx, g_get_prgname() );
        sn_launcher_context_set_binary_name( ctx, argv[ 0 ] );

        sn_launcher_context_set_workspace ( ctx, tvsn_get_active_workspace_number( screen ) );

        /* FIXME: I don't think this is correct, other people seem to use CurrentTime here.
                  However, using CurrentTime causes problems, so I so it like this.
                  Maybe this is incorrect, but it works, so, who cares?
        */
        /* time( &cur_time ); */
        sn_launcher_context_initiate( ctx, g_get_prgname(),
                                      argv[ 0 ], gtk_get_current_event_time() /*cur_time*/ );

        setup_func = (GSpawnChildSetupFunc) sn_launcher_context_setup_child_process;
        if( startup_id_index >= 0 )
            g_free( new_env[i] );
        else
            startup_id_index = i++;
        new_env[ startup_id_index ] = g_strconcat( "DESKTOP_STARTUP_ID=",
                                      sn_launcher_context_get_startup_id ( ctx ), NULL );
    }
#endif

    /* This is taken from gdk_spawn_on_screen */
    display_name = gdk_screen_make_display_name ( screen );
    if ( display_index >= 0 )
        new_env[ display_index ] = g_strconcat( "DISPLAY=", display_name, NULL );
    else
        new_env[ i++ ] = g_strconcat( "DISPLAY=", display_name, NULL );

    g_free( display_name );
    new_env[ i ] = NULL;

    ret = g_spawn_async( work_dir,
                         argv,  new_env,
                         flags,
                         NULL, NULL,
                         NULL, err );

    /* for debugging */
#if 0
    g_debug( "debug vfs_execute_on_screen(): flags: %d, display_index=%d", flags, display_index );
    for( i = 0; argv[i]; ++i ) {
        g_debug( "argv[%d] = \"%s\"" , i, argv[i] );
    }
    for( i = 0; i < n_env /*new_env[i]*/; ++i ) {
        g_debug( "new_env[%d] = \"%s\"" , i, new_env[i] );
    }
    if( ret )
        g_debug( "the program was executed without error" );
    else
        g_debug( "launch failed: %s", (*err)->message );
#endif

    g_strfreev( new_env );

#ifdef HAVE_SN
    if ( G_LIKELY ( ctx ) )
    {
        if ( G_LIKELY ( ret ) )
            g_timeout_add ( 20 * 1000, sn_timeout, ctx );
        else
        {
            sn_launcher_context_complete ( ctx );
            sn_launcher_context_unref ( ctx );
        }
    }

    if ( G_LIKELY ( display ) )
        sn_display_unref ( display );
#endif

    return ret;
}
示例#19
0
文件: camera.c 项目: avsmal/darktable
static void _show_property_popupmenu_clicked(GtkWidget *widget, gpointer user_data)
{
  dt_lib_camera_t *lib = (dt_lib_camera_t *)user_data;
  gtk_menu_popup(lib->gui.properties_menu, NULL, NULL, NULL, NULL, 1, gtk_get_current_event_time());
}
static gboolean
activate_panel (GnomeControlCenter *shell,
                const gchar        *id,
		const gchar       **argv,
                const gchar        *desktop_file,
                const gchar        *name,
                GIcon              *gicon)
{
  GDesktopAppInfo     *appinfo;
  GdkAppLaunchContext *context;
  GdkScreen           *screen;
  GdkDisplay          *display;
  GError              *error;

  appinfo = g_desktop_app_info_new_from_filename (desktop_file);

  screen = gtk_widget_get_screen (shell->priv->window);
  display = gdk_screen_get_display (screen);
  context = gdk_display_get_app_launch_context (display);
  gdk_app_launch_context_set_screen (context, screen);
  gdk_app_launch_context_set_timestamp (context, gtk_get_current_event_time ());

  error = NULL;
  g_app_info_launch_uris (G_APP_INFO (appinfo), NULL,
                          (GAppLaunchContext *) context,
                          &error);

  if (error) {
    g_printerr ("Could not launch '%s': %s\n", id, error->message);
    g_clear_error (&error);
  }

  g_object_unref (context);
  g_object_unref (appinfo);
#if 0
  GnomeControlCenterPrivate *priv = shell->priv;
  GType panel_type = G_TYPE_INVALID;
  GList *panels, *l;
  GtkWidget *box;
  const gchar *icon_name;

  /* check if there is an plugin that implements this panel */
  panels = g_io_extension_point_get_extensions (priv->extension_point);

  if (!desktop_file)
    return FALSE;
  if (!id)
    return FALSE;

  for (l = panels; l != NULL; l = l->next)
    {
      GIOExtension *extension;
      const gchar *name;

      extension = l->data;

      name = g_io_extension_get_name (extension);

      if (!g_strcmp0 (name, id))
        {
          panel_type = g_io_extension_get_type (extension);
          break;
        }
    }

  if (panel_type == G_TYPE_INVALID)
    {
      g_warning ("Could not find the loadable module for panel '%s'", id);
      return FALSE;
    }

  /* create the panel plugin */
  priv->current_panel = g_object_new (panel_type, "shell", shell, "argv", argv, NULL);
  cc_shell_set_active_panel (CC_SHELL (shell), CC_PANEL (priv->current_panel));
  gtk_widget_show (priv->current_panel);

  gtk_lock_button_set_permission (GTK_LOCK_BUTTON (priv->lock_button),
                                  cc_panel_get_permission (CC_PANEL (priv->current_panel)));

  box = gtk_alignment_new (0, 0, 1, 1);
  gtk_alignment_set_padding (GTK_ALIGNMENT (box), 6, 6, 6, 6);

  gtk_container_add (GTK_CONTAINER (box), priv->current_panel);

  gtk_widget_set_name (box, id);
  notebook_add_page (priv->notebook, box);

  /* switch to the new panel */
  gtk_widget_show (box);
  notebook_select_page (priv->notebook, box);

  /* set the title of the window */
  icon_name = get_icon_name_from_g_icon (gicon);
  gtk_window_set_role (GTK_WINDOW (priv->window), id);
  gtk_window_set_title (GTK_WINDOW (priv->window), name);
  gtk_window_set_default_icon_name (icon_name);
  gtk_window_set_icon_name (GTK_WINDOW (priv->window), icon_name);

  priv->current_panel_box = box;
#endif
  return TRUE;
}
示例#21
0
static void on_treeview_popup_menu(void)
{
	gtk_menu_popup(gui.menu_treeview, NULL, NULL, NULL, NULL, 0,
		gtk_get_current_event_time());
}