static void indicator_update_icon(PurpleStatusPrimitive status, gboolean connecting, gboolean pending) { const gchar *icon_name = NULL; sStatus = status; switch (status) { case PURPLE_STATUS_OFFLINE: icon_name = PIDGIN_STOCK_TRAY_OFFLINE; break; case PURPLE_STATUS_AWAY: icon_name = PIDGIN_STOCK_TRAY_AWAY; break; case PURPLE_STATUS_UNAVAILABLE: icon_name = PIDGIN_STOCK_TRAY_BUSY; break; case PURPLE_STATUS_EXTENDED_AWAY: icon_name = PIDGIN_STOCK_TRAY_XA; break; case PURPLE_STATUS_INVISIBLE: icon_name = PIDGIN_STOCK_TRAY_INVISIBLE; break; default: icon_name = PIDGIN_STOCK_TRAY_AVAILABLE; break; } if (pending) icon_name = PIDGIN_STOCK_TRAY_PENDING; if (connecting) icon_name = PIDGIN_STOCK_TRAY_CONNECT; if (icon_name) { app_indicator_set_icon(sIndicator, icon_name); } }
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; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); mainWindow = this; // Start device manager KbManager::init(CKB_VERSION_STR); connect(KbManager::kbManager(), SIGNAL(kbConnected(Kb*)), this, SLOT(addDevice(Kb*))); connect(KbManager::kbManager(), SIGNAL(kbDisconnected(Kb*)), this, SLOT(removeDevice(Kb*))); connect(KbManager::kbManager(), SIGNAL(versionUpdated()), this, SLOT(updateVersion())); connect(KbManager::scanTimer(), SIGNAL(timeout()), this, SLOT(timerTick())); // Set up tray icon restoreAction = new QAction(tr("Restore"), this); closeAction = new QAction(tr("Quit ckb"), this); #ifdef USE_LIBAPPINDICATOR QString desktop = std::getenv("XDG_CURRENT_DESKTOP"); unityDesktop = (desktop.toLower() == "unity"); if(unityDesktop){ trayIcon = 0; indicatorMenu = gtk_menu_new(); indicatorMenuRestoreItem = gtk_menu_item_new_with_label("Restore"); indicatorMenuQuitItem = gtk_menu_item_new_with_label("Quit ckb"); gtk_menu_shell_append(GTK_MENU_SHELL(indicatorMenu), indicatorMenuRestoreItem); gtk_menu_shell_append(GTK_MENU_SHELL(indicatorMenu), indicatorMenuQuitItem); g_signal_connect(indicatorMenuQuitItem, "activate", G_CALLBACK(quitIndicator), this); g_signal_connect(indicatorMenuRestoreItem, "activate", G_CALLBACK(restoreIndicator), this); gtk_widget_show(indicatorMenuRestoreItem); gtk_widget_show(indicatorMenuQuitItem); indicator = app_indicator_new("ckb", "indicator-messages", APP_INDICATOR_CATEGORY_APPLICATION_STATUS); app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE); app_indicator_set_menu(indicator, GTK_MENU(indicatorMenu)); app_indicator_set_icon(indicator, "ckb"); } else #endif // USE_LIBAPPINDICATOR { trayIconMenu = new QMenu(this); trayIconMenu->addAction(restoreAction); trayIconMenu->addAction(closeAction); trayIcon = new QSystemTrayIcon(QIcon(":/img/ckb-logo.png"), this); trayIcon->setContextMenu(trayIconMenu); connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(iconClicked(QSystemTrayIcon::ActivationReason))); } toggleTrayIcon(!CkbSettings::get("Program/SuppressTrayIcon").toBool()); #ifdef Q_OS_MACX // Make a custom "Close" menu action for OSX, as the default one brings up the "still running" popup unnecessarily QMenuBar* menuBar = new QMenuBar(this); setMenuBar(menuBar); this->menuBar()->addMenu("ckb")->addAction(closeAction); #else // On linux, add a handler for Ctrl+Q new QShortcut(QKeySequence("Ctrl+Q"), this, SLOT(quitApp())); #endif connect(ui->actionExit, SIGNAL(triggered()), this, SLOT(quitApp())); connect(closeAction, SIGNAL(triggered()), this, SLOT(quitApp())); connect(restoreAction, SIGNAL(triggered()), this, SLOT(showWindow())); connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(stateChange(Qt::ApplicationState))); connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(cleanup())); ui->tabWidget->addTab(settingsWidget = new SettingsWidget(this), configLabel); settingsWidget->setVersion("ckb " CKB_VERSION_STR); }
static void indicator_blank_icon(void) { app_indicator_set_icon(sIndicator, "pidgin-indicator-nothing"); }