Esempio n. 1
0
gboolean tray_embedded_cb (GtkStatusIcon *status_icon, GParamSpec *pspec, gpointer user_data)
{
  if (gtk_status_icon_is_embedded(tray_icon)) {
    reload_tray_icon();
  }
  return TRUE;
}
Esempio n. 2
0
void load_tray_icon()
{
  if (!hime_status_tray)
    return;
  if (!tray_icon) {
    create_tray(NULL);
    return;
  }
  // wrong width & height if it is not embedded-ready
  if (!gtk_status_icon_is_embedded(tray_icon))
    return;
  iw = gtk_status_icon_get_size(tray_icon), ih = gtk_status_icon_get_size(tray_icon);
  if (!pixbuf) {
    char icon_fname[128];
    get_icon_path(HIME_TRAY_PNG, icon_fname);
    pixbuf = gdk_pixbuf_new_from_file_at_size(icon_fname, iw, ih, NULL);
  }
  char *iconame = HIME_TRAY_PNG;
//  if (current_CS && current_CS->in_method && inmd)
// Workaround due to issue #161
  if (current_CS && current_CS->im_state != HIME_STATE_DISABLED && current_CS->im_state != HIME_STATE_ENG_FULL)
    iconame = inmd[current_CS->in_method].icon;
  char fname[512];
  if (iconame)
    get_icon_path(iconame, fname);
  if (strcmp(pixbuf_ch_fname, fname) && pixbuf_ch) {
    g_object_unref(pixbuf_ch); pixbuf_ch = NULL;
  }
  if (!pixbuf_ch) {
    strcpy(pixbuf_ch_fname, fname);
    pixbuf_ch = gdk_pixbuf_new_from_file_at_size(fname, iw, ih, NULL);
  }
  draw_icon();
  iconame = NULL;
}
Esempio n. 3
0
static void on_scroll(GtkStatusIcon *status_icon, GdkEventScroll *event, gpointer data)
{
    // Do nothing unless we have been updated at least once
    if (!updated_once)
        return;

    // Bump the volume level
    switch (event->direction) {
        case GDK_SCROLL_UP:
        case GDK_SCROLL_RIGHT:
            audio_status_raise_volume();
            break;
        case GDK_SCROLL_DOWN:
        case GDK_SCROLL_LEFT:
            audio_status_lower_volume();
            break;
        default:
            return;
    }

    // Sync with the server
    pulse_glue_sync_volume();

    // Inform the user by flashing the volume scale
    update_volume_scale();
    if (gtk_status_icon_is_embedded(tray_icon)) {
        GdkRectangle rect;
        gtk_status_icon_get_geometry(tray_icon, NULL, &rect, NULL);
        flash_volume_scale(&rect);
    }
    else {
        flash_volume_scale(NULL);
    }
}
Esempio n. 4
0
static void on_activate(GtkStatusIcon *status_icon, gpointer data)
{
    // Do nothing unless we have been updated at least once
    if (!updated_once)
        return;

    // Hide the volume scale if it's visible
    if (is_volume_scale_visible()) {
        hide_volume_scale();
        return;
    }

    // If we're showing the menu, just hide it
    if (is_popup_menu_visible()) {
        hide_popup_menu();
        return;
    }

    // Show the volume scale
    if (gtk_status_icon_is_embedded(tray_icon)) {
        GdkRectangle rect;
        gtk_status_icon_get_geometry(tray_icon, NULL, &rect, NULL);
        show_volume_scale(&rect);
    }
    else {
        show_volume_scale(NULL);
    }
}
Esempio n. 5
0
File: gicon.c Progetto: S010/test
void
on_isembed_get_clicked(GtkWidget *widget, gpointer data)
{
	GtkEntry *entry = data;
	gboolean val;

	val = gtk_status_icon_is_embedded(status_icon);
	if (val)
		gtk_entry_set_text(entry, "true");
	else
		gtk_entry_set_text(entry, "false");
}
Esempio n. 6
0
gboolean notification_trayicon_is_available(void)
{
	gboolean is_available;
	is_available = FALSE;

	if(trayicon) {
		if(gtk_status_icon_is_embedded(trayicon) &&
			 gtk_status_icon_get_visible(trayicon))
			is_available = TRUE;
	}

	return is_available;
}
Esempio n. 7
0
static void
tray_menu_notify_cb (GObject *tray, GParamSpec *pspec, gpointer user_data)
{
	if (sticon)
	{
		if (!gtk_status_icon_is_embedded (sticon))
		{
			tray_restore_timer = g_timeout_add(500, (GSourceFunc)tray_menu_try_restore, NULL);
		}
		else
		{
			if (tray_restore_timer)
			{
				g_source_remove (tray_restore_timer);
				tray_restore_timer = 0;
			}
		}
	}
}
Esempio n. 8
0
void
enable_systray_changed_cb (GtkComboBox *widget, gpointer user_data) {

    GUI *appGUI = (GUI *)user_data;

    if (!appGUI->opt->callback_active) return;

    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(appGUI->opt->enable_systray_checkbutton)) == TRUE) {
        config.enable_systray = 1;
        gtk_widget_set_sensitive(appGUI->opt->start_minimised_checkbutton, TRUE);
        gtk_status_icon_set_visible(appGUI->osmo_trayicon, TRUE);
        if (gtk_status_icon_is_embedded(appGUI->osmo_trayicon) == FALSE) {
            appGUI->no_tray = TRUE;
        }
    } else {
        config.enable_systray = 0;
        gtk_status_icon_set_visible(appGUI->osmo_trayicon, FALSE);
        gtk_widget_set_sensitive(appGUI->opt->start_minimised_checkbutton, FALSE);
    }
}
Esempio n. 9
0
static void
embedded_changed_cb (GtkStatusIcon *icon)
{
  g_print ("status icon %p embedded changed to %d\n", icon,
	   gtk_status_icon_is_embedded (icon));
}
Esempio n. 10
0
static gboolean
handle_stdin (GIOChannel * channel, GIOCondition condition, gpointer data)
{
  if ((condition & G_IO_IN) != 0)
    {
      GString *string;
      GError *err = NULL;

      string = g_string_new (NULL);
      while (channel->is_readable == FALSE);

      do
        {
          gint status;
          gchar *command = NULL, *value = NULL, **args;

          do
            {
              status = g_io_channel_read_line_string (channel, string, NULL, &err);

              while (gdk_events_pending ())
                gtk_main_iteration ();
            }
          while (status == G_IO_STATUS_AGAIN);

          if (status != G_IO_STATUS_NORMAL)
            {
              if (err)
                {
                  g_printerr ("yad_notification_handle_stdin(): %s\n", err->message);
                  g_error_free (err);
                  err = NULL;
                }
              /* stop handling but not exit */
              g_io_channel_shutdown (channel, TRUE, NULL);
              return FALSE;
            }

          strip_new_line (string->str);
          if (!string->str[0])
            continue;

          args = g_strsplit (string->str, ":", 2);
          command = g_strdup (args[0]);
          if (args[1])
            value = g_strdup (args[1]);
          g_strfreev (args);
          if (value)
            g_strstrip (value);

          if (!g_ascii_strcasecmp (command, "icon") && value)
            {
              g_free (icon);
              icon = g_strdup (value);

              if (gtk_status_icon_get_visible (status_icon) && gtk_status_icon_is_embedded (status_icon))
                set_icon ();
            }
          else if (!g_ascii_strcasecmp (command, "tooltip"))
            {
              if (g_utf8_validate (value, -1, NULL))
                {
                  gchar *message = g_strcompress (value);
                  if (!options.data.no_markup)
                    gtk_status_icon_set_tooltip_markup (status_icon, message);
                  else
                    gtk_status_icon_set_tooltip_text (status_icon, message);
                  g_free (message);
                }
              else
                g_printerr (_("Invalid UTF-8 in tooltip!\n"));
            }
          else if (!g_ascii_strcasecmp (command, "visible"))
            {
#if !GTK_CHECK_VERSION(2,22,0)
              if (!g_ascii_strcasecmp (value, "blink"))
                {
                  gboolean state = gtk_status_icon_get_blinking (status_icon);
                  gtk_status_icon_set_blinking (status_icon, !state);
                }
              else
#endif
              if (!g_ascii_strcasecmp (value, "false"))
                {
                  gtk_status_icon_set_visible (status_icon, FALSE);
#if !GTK_CHECK_VERSION(2,22,0)
                  gtk_status_icon_set_blinking (status_icon, FALSE);
#endif
                }
              else
                {
                  gtk_status_icon_set_visible (status_icon, TRUE);
#if !GTK_CHECK_VERSION(2,22,0)
                  gtk_status_icon_set_blinking (status_icon, FALSE);
#endif
                }
            }
          else if (!g_ascii_strcasecmp (command, "action"))
            {
              g_free (action);
              if (value)
                action = g_strdup (value);
            }
          else if (!g_ascii_strcasecmp (command, "quit"))
            {
              exit_code = YAD_RESPONSE_OK;
              gtk_main_quit ();
            }
          else if (!g_ascii_strcasecmp (command, "menu"))
            {
              if (value)
                parse_menu_str (value);
            }
          else
            g_printerr (_("Unknown command '%s'\n"), command);

          g_free (command);
          g_free (value);
        }
      while (g_io_channel_get_buffer_condition (channel) == G_IO_IN);
      g_string_free (string, TRUE);
    }

  if ((condition & G_IO_HUP) != 0)
    {
      g_io_channel_shutdown (channel, TRUE, NULL);
      gtk_main_quit ();
      return FALSE;
    }

  return TRUE;
}
Esempio n. 11
0
gboolean clock_check(gpointer dummy)
{
	if (dummy) {};

	int xneur_pid = -1;
	char *ps_command = (char *) malloc(1024 * sizeof(char));
	if (xneur_old_pid == -1)
		xneur_old_pid = 1;
	snprintf(ps_command, 1024, "ps -p %d | grep xneur", xneur_old_pid);
	FILE *fp = popen(ps_command, "r");
	free (ps_command);
	if (fp != NULL)
	{
		char buffer[NAME_MAX];
		if (fgets(buffer, NAME_MAX, fp) != NULL)
			xneur_pid = xneur_old_pid;
	
		pclose(fp);
	}
	if (xneur_pid == -1)
		xneur_pid = xconfig->get_pid(xconfig);
	
	
	int xneur_state = xconfig->manual_mode;
	int xneur_group = get_active_kbd_group(dpy);

	if (get_kbd_group_count(dpy) != xconfig->handle->total_languages)
	{
		for (int i = 0; i < MAX_LAYOUTS; i++)
		{
			if (tray->images[i] != NULL)
				g_free(tray->images[i]);
		}

		gtk_widget_destroy(GTK_WIDGET(tray->menu));
		tray->menu = NULL;
		
		g_spawn_command_line_async(PACKAGE, NULL);
		
		gtk_main_quit();
	}


	if  (xneur_pid == xneur_old_pid &&
	     xneur_state == xneur_old_state &&
	    xneur_group == xneur_old_group &&
	    force_update == FALSE)
		return TRUE;
	
	force_update = FALSE;

	xneur_old_pid = xneur_pid;
	xneur_old_state = xneur_state;
	xneur_old_group = xneur_group;
		
	int lang = get_active_kbd_group(dpy);
	
	gchar *hint;
	gchar *status_text;
	//float saturation = 1.0;
	if (xneur_pid != -1)
	{
		//saturation = 1.0;
		hint = g_strdup_printf("%s%s%s", _("X Neural Switcher running ("), xconfig->handle->languages[lang].dir, ")");
		status_text = g_strdup_printf("%s", _("Stop daemon"));
	}
	else
	{
		//saturation = 0.25;
		hint = g_strdup_printf("%s%s%s", _("X Neural Switcher stopped ("), xconfig->handle->languages[lang].dir, ")");
		status_text = g_strdup_printf("%s", _("Start daemon"));
	}

	gtk_menu_item_set_label(GTK_MENU_ITEM(tray->status), status_text);

	gint kbd_gr = get_active_kbd_group(dpy);


	const char *icon_name = get_tray_icon_name(tray->images[kbd_gr]);
	if (tray->tray_icon)
	{
		gtk_widget_hide_all(GTK_WIDGET(tray->tray_icon));
		gtk_widget_destroy (tray->image);
		if (strcasecmp(show_in_the_tray, "Text") == 0)
		{
			char *layout_name = strdup(xconfig->handle->languages[kbd_gr].dir);
			for (unsigned int i=0; i < strlen(layout_name); i++)
				layout_name[i] = toupper(layout_name[i]); 
			tray->image = gtk_label_new ((const gchar *)layout_name);
			gtk_label_set_justify (GTK_LABEL(tray->image), GTK_JUSTIFY_CENTER);
			free(layout_name);
		}
		else
		{
			tray->image = gtk_image_new_from_icon_name(icon_name, GTK_ICON_SIZE_LARGE_TOOLBAR);
		}
		gtk_container_add(GTK_CONTAINER(tray->evbox), tray->image);
		gtk_widget_show_all(GTK_WIDGET(tray->tray_icon));
	}
	else if (tray->status_icon)
	{
		if (gtk_status_icon_is_embedded(tray->status_icon))
		{					
			if (strcasecmp(show_in_the_tray, "Text") == 0)
			{
				char *layout_name = strdup(xconfig->handle->languages[kbd_gr].dir);
				for (unsigned int i=0; i < strlen(layout_name); i++)
					layout_name[i] = toupper(layout_name[i]);

				GdkPixbuf *pb = text_to_gtk_pixbuf (layout_name);
				free(layout_name);
				pb = gdk_pixbuf_add_alpha(pb, TRUE, 255, 255, 255);
				gtk_status_icon_set_from_pixbuf(tray->status_icon, pb);
				g_object_unref(pb);
			}
			else
			{
				gtk_status_icon_set_from_icon_name(tray->status_icon, icon_name);
			}

			gtk_status_icon_set_tooltip(tray->status_icon, hint);
		}	
	}
#ifdef HAVE_APP_INDICATOR
	else if (tray->app_indicator)
	{
		char *layout_name = strdup(xconfig->handle->languages[kbd_gr].name);
		if (strcasecmp(show_in_the_tray, "Text") == 0)
		{
#ifdef HAVE_DEPREC_APP_INDICATOR	
			app_indicator_set_icon (tray->app_indicator, icon_name);
#else
			app_indicator_set_label (tray->app_indicator, layout_name, layout_name);
			app_indicator_set_icon (tray->app_indicator, "");
#endif
		}
		else
		{
#ifdef HAVE_DEPREC_APP_INDICATOR
			app_indicator_set_icon (tray->app_indicator, icon_name);
#else
			app_indicator_set_icon (tray->app_indicator, icon_name);
			app_indicator_set_label (tray->app_indicator,"", "");
#endif
		}
		free(layout_name);
	}
#endif

	g_free (hint);
	g_free (status_text);

	return TRUE;
}