/* Handler for "clicked" signal on main widget. */ static gboolean wincmd_button_clicked(GtkWidget * widget, GdkEventButton * event, LXPanel * panel) { WinCmdPlugin * wc = lxpanel_plugin_get_data(widget); /* Left-click to iconify. */ if (event->button == 1) { GdkScreen* screen = gtk_widget_get_screen(widget); static GdkAtom atom = 0; if( G_UNLIKELY(0 == atom) ) atom = gdk_atom_intern("_NET_SHOWING_DESKTOP", FALSE); /* If window manager supports _NET_SHOWING_DESKTOP, use it. * Otherwise, fall back to iconifying windows individually. */ if (gdk_x11_screen_supports_net_wm_hint(screen, atom)) { int showing_desktop = ((( ! wc->toggle_preference) || ( ! wc->toggle_state)) ? 1 : 0); Xclimsg(DefaultRootWindow(GDK_DISPLAY_XDISPLAY(gdk_display_get_default())), a_NET_SHOWING_DESKTOP, showing_desktop, 0, 0, 0, 0); wincmd_adjust_toggle_state(wc); } else wincmd_execute(wc, WC_ICONIFY); } /* Middle-click to shade. */ else if (event->button == 2) wincmd_execute(wc, WC_SHADE); return TRUE; }
/* Callback when the configuration dialog has recorded a configuration change. */ static gboolean dirmenu_apply_configuration(gpointer user_data) { GtkWidget * p = user_data; DirMenuPlugin * dm = lxpanel_plugin_get_data(p); char * path = dm->path; /* Normalize path */ if (path == NULL) dm->path = g_strdup(fm_get_home_dir()); else if (path[0] == '~') { dm->path = expand_tilda(path); g_free(path); } /* Save configuration */ config_group_set_string(dm->settings, "path", dm->path); config_group_set_string(dm->settings, "name", dm->name); config_group_set_string(dm->settings, "image", dm->image); lxpanel_button_set_icon(p, ((dm->image != NULL) ? dm->image : "file-manager"), -1); lxpanel_button_set_label(p, dm->name); gtk_widget_set_tooltip_text(p, dm->path); return FALSE; }
/* Position-calculation callback for popup menu. */ static void dirmenu_popup_set_position(GtkWidget * menu, gint * px, gint * py, gboolean * push_in, GtkWidget * p) { DirMenuPlugin * dm = lxpanel_plugin_get_data(p); /* Determine the coordinates. */ lxpanel_plugin_popup_set_position_helper(dm->panel, p, menu, px, py); *push_in = TRUE; }
/* Callback when the configuration dialog is to be shown. */ static GtkWidget *wincmd_configure(LXPanel *panel, GtkWidget *p) { WinCmdPlugin * wc = lxpanel_plugin_get_data(p); return lxpanel_generic_config_dlg(_("Minimize All Windows"), panel, wincmd_apply_configuration, p, _("Alternately iconify/shade and raise"), &wc->toggle_preference, CONF_TYPE_BOOL, /* FIXME: configure buttons 1 and 2 */ NULL); }
/* Callback when the configuration dialog is to be shown. */ static GtkWidget *dirmenu_configure(LXPanel *panel, GtkWidget *p) { DirMenuPlugin * dm = lxpanel_plugin_get_data(p); return lxpanel_generic_config_dlg(_("Directory Menu"), panel, dirmenu_apply_configuration, p, _("Directory"), &dm->path, CONF_TYPE_DIRECTORY_ENTRY, _("Label"), &dm->name, CONF_TYPE_STR, _("Icon"), &dm->image, CONF_TYPE_FILE_ENTRY, NULL); }
/* Handler for button-press-event on top level widget. */ static gboolean dirmenu_button_press_event(GtkWidget * widget, GdkEventButton * event, LXPanel * p) { DirMenuPlugin * dm = lxpanel_plugin_get_data(widget); if (event->button == 1) { dirmenu_show_menu(widget, dm, event->button, event->time); return TRUE; } return FALSE; }
/* Callback when the configuration dialog is to be shown. */ static GtkWidget *space_configure(Panel *panel, GtkWidget *instance, GtkWindow *parent) { SpacePlugin * sp = lxpanel_plugin_get_data(instance); GtkWidget * dlg; dlg = lxpanel_generic_config_dlg(_("Spacer"), panel, space_apply_configuration, instance, _("Size"), &sp->size, CONF_TYPE_INT, NULL); gtk_widget_set_size_request(dlg, 200, -1); /* Improve geometry */ return dlg; }
static gboolean monitors_button_press_event(GtkWidget* widget, GdkEventButton* evt, LXPanel *panel) { MonitorsPlugin* mp = lxpanel_plugin_get_data(widget); if (mp->action != NULL) fm_launch_command_simple(NULL, NULL, 0, mp->action, NULL); else fm_launch_command_simple(NULL, NULL, 0, "lxtask", NULL); return TRUE; }
/* Callback when the configuration dialog has recorded a configuration change. */ static gboolean space_apply_configuration(gpointer user_data) { GtkWidget * p = user_data; SpacePlugin * sp = lxpanel_plugin_get_data(p); /* Apply settings. */ if (panel_get_orientation(sp->panel) == GTK_ORIENTATION_HORIZONTAL) gtk_widget_set_size_request(p, sp->size, 2); else gtk_widget_set_size_request(p, 2, sp->size); /* Save config values */ config_group_set_int(sp->settings, "Size", sp->size); return FALSE; }
/* Callback when the configuration dialog has recorded a configuration change. */ static gboolean wincmd_apply_configuration(gpointer user_data) { GtkWidget * p = user_data; WinCmdPlugin * wc = lxpanel_plugin_get_data(p); /* Just save settings */ config_group_set_string(wc->settings, "image", wc->image); config_group_set_string(wc->settings, "Button1", wincmd_names[wc->button_1_command]); config_group_set_string(wc->settings, "Button2", wincmd_names[wc->button_2_command]); config_group_set_int(wc->settings, "Toggle", wc->toggle_preference); return FALSE; }
static void menu_pos(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, GtkWidget *widget) { int ox, oy, w, h; kano_feedback_plugin_t *plugin = lxpanel_plugin_get_data(widget); GtkAllocation allocation; gtk_widget_get_allocation(GTK_WIDGET(widget), &allocation); gdk_window_get_origin(gtk_widget_get_window(widget), &ox, &oy); /* FIXME The X origin is being truncated for some reason, reset it from the allocaation. */ ox = allocation.x; #if GTK_CHECK_VERSION(2,20,0) GtkRequisition requisition; gtk_widget_get_requisition(GTK_WIDGET(menu), &requisition); w = requisition.width; h = requisition.height; #else w = GTK_WIDGET(menu)->requisition.width; h = GTK_WIDGET(menu)->requisition.height; #endif if (panel_get_orientation(plugin->panel) == GTK_ORIENTATION_HORIZONTAL) { *x = ox; if (*x + w > gdk_screen_width()) *x = ox + allocation.width - w; *y = oy - h; if (*y < 0) *y = oy + allocation.height; } else { *x = ox + allocation.width; if (*x > gdk_screen_width()) *x = ox - w; *y = oy; if (*y + h > gdk_screen_height()) *y = oy + allocation.height - h; } /* Debugging prints */ /*printf("widget: x,y=%d,%d w,h=%d,%d\n", ox, oy, allocation.width, allocation.height ); printf("w-h %d %d\n", w, h); */ *push_in = TRUE; return; }
static void on_volume_focus (GtkWidget* dlg, GdkEventFocus *event, GtkWidget *p) { volume_t *vol = lxpanel_plugin_get_data(p); if (! vol_spin) return; GtkAdjustment *vol_adjustment = gtk_spin_button_get_adjustment (vol_spin); if (! vol_adjustment) return; curr_volume = gtk_adjustment_get_value (vol_adjustment); update_icon(p, vol); /* FIXME: use smarter method */ gtk_widget_destroy( dlg ); vol->dlg = NULL; }
static GtkWidget *config(LXPanel *panel, GtkWidget *p) { ENTER; GtkWidget *dialog; thermal *th = lxpanel_plugin_get_data(p); dialog = lxpanel_generic_config_dlg(_("Temperature Monitor"), panel, applyConfig, p, _("Normal color"), &th->str_cl_normal, CONF_TYPE_STR, _("Warning1 color"), &th->str_cl_warning1, CONF_TYPE_STR, _("Warning2 color"), &th->str_cl_warning2, CONF_TYPE_STR, _("Automatic sensor location"), &th->auto_sensor, CONF_TYPE_BOOL, _("Sensor"), &th->sensor, CONF_TYPE_STR, _("Automatic temperature levels"), &th->not_custom_levels, CONF_TYPE_BOOL, _("Warning1 temperature"), &th->warning1, CONF_TYPE_INT, _("Warning2 temperature"), &th->warning2, CONF_TYPE_INT, NULL); RET(dialog); }
static GtkWidget * monitors_config (LXPanel *panel, GtkWidget *p) { ENTER; GtkWidget *dialog; MonitorsPlugin *mp; mp = lxpanel_plugin_get_data(p); dialog = lxpanel_generic_config_dlg(_("Resource monitors"), panel, monitors_apply_config, p, _("Display CPU usage"), &mp->displayed_monitors[0], CONF_TYPE_BOOL, _("CPU color"), &colors[CPU_POSITION], CONF_TYPE_STR, _("Display RAM usage"), &mp->displayed_monitors[1], CONF_TYPE_BOOL, _("RAM color"), &colors[MEM_POSITION], CONF_TYPE_STR, _("Action when clicked (default: lxtask)"), &mp->action, CONF_TYPE_STR, NULL); RET(dialog); }
static gboolean applyConfig(gpointer p) { thermal *th = lxpanel_plugin_get_data(p); int critical; ENTER; if (th->str_cl_normal) gdk_color_parse(th->str_cl_normal, &th->cl_normal); if (th->str_cl_warning1) gdk_color_parse(th->str_cl_warning1, &th->cl_warning1); if (th->str_cl_warning2) gdk_color_parse(th->str_cl_warning2, &th->cl_warning2); remove_all_sensors(th); if(th->sensor == NULL) th->auto_sensor = TRUE; if(th->auto_sensor) check_sensors(th); else if (strncmp(th->sensor, "/sys/", 5) != 0) add_sensor(th, th->sensor, th->sensor, proc_get_temperature, proc_get_critical); else if (strncmp(th->sensor, "/sys/class/hwmon/", 17) != 0) add_sensor(th, th->sensor, th->sensor, sysfs_get_temperature, sysfs_get_critical); else add_sensor(th, th->sensor, th->sensor, hwmon_get_temperature, hwmon_get_critical); critical = get_critical(th); if(th->not_custom_levels){ th->warning1 = critical - 10; th->warning2 = critical - 5; } config_group_set_string(th->settings, "NormalColor", th->str_cl_normal); config_group_set_string(th->settings, "Warning1Color", th->str_cl_warning1); config_group_set_string(th->settings, "Warning2Color", th->str_cl_warning2); config_group_set_int(th->settings, "AutomaticLevels", th->not_custom_levels); /* TODO: clean obsolete setting config_setting_remove(th->settings, "CustomLevels"); */ config_group_set_int(th->settings, "Warning1Temp", th->warning1); config_group_set_int(th->settings, "Warning2Temp", th->warning2); config_group_set_int(th->settings, "AutomaticSensor", th->auto_sensor); config_group_set_string(th->settings, "Sensor", th->sensor); RET(FALSE); }
static gboolean on_button_press (GtkWidget* widget, GdkEventButton* evt, LXPanel* p) { volume_t *vol = lxpanel_plugin_get_data(widget); /* for scroll correction */ if (skip_botton1_event) { gtk_widget_destroy(vol->dlg); vol->dlg = NULL; skip_botton1_event = FALSE; } switch ( evt->button ) { case 1: { /* Left click */ if ( ! vol->dlg ) { vol->dlg = create_volume_window(); /* setting background to default */ gtk_widget_set_style(vol->dlg, panel_get_defstyle(p)); g_signal_connect( vol->dlg, "focus-out-event", G_CALLBACK(on_volume_focus), widget ); gtk_window_present( GTK_WINDOW(vol->dlg) ); } else { /* update icon */ if (! vol_spin) return FALSE; GtkAdjustment *vol_adjustment = gtk_spin_button_get_adjustment (vol_spin); if (! vol_adjustment) return FALSE; curr_volume = gtk_adjustment_get_value (vol_adjustment); update_icon(widget, vol); gtk_widget_destroy(vol->dlg); vol->dlg = NULL; } break; } case 2: { /* middle mouse button */ if ( ! vol->dlg ) { vol->dlg = create_volume_window(); } if (! vol_spin) return FALSE; GtkAdjustment *vol_adjustment = gtk_spin_button_get_adjustment (vol_spin); if (! vol_adjustment) return FALSE; curr_volume = gtk_adjustment_get_value (vol_adjustment); if (curr_volume > 0) { /* turning to mute */ vol_before_mute = curr_volume; curr_volume = 0; } else { curr_volume = vol_before_mute; } gtk_adjustment_set_value (vol_adjustment, curr_volume); gtk_spin_button_set_adjustment(vol_spin, vol_adjustment); update_icon(widget, vol); gtk_widget_destroy( vol->dlg ); vol->dlg = NULL; break; } default: /* never here */ break; } return FALSE; }
static gboolean monitors_apply_config (gpointer user_data) { ENTER; GtkWidget *p = user_data; MonitorsPlugin *mp; mp = lxpanel_plugin_get_data(p); int i; int current_n_monitors = 0; start: for (i = 0; i < N_MONITORS; i++) { if (mp->displayed_monitors[i]) current_n_monitors++; if (mp->displayed_monitors[i] && !mp->monitors[i]) { /* We've just activated monitor<i> */ mp->monitors[i] = monitors_add_monitor(p, mp, update_functions[i], tooltip_update[i], colors[i]); /* * It is probably best for users if their monitors are always * displayed in the same order : the CPU monitor always on the left, * the RAM monitor always on the right of the CPU monitor (if the * CPU monitor is displayed), etc. That's why we do not just use * gtk_box_pack_start/gtk_box_pack_end, and use * gtk_box_reorder_child. */ gtk_box_reorder_child(GTK_BOX(p), mp->monitors[i]->da,current_n_monitors-1); } else if (!mp->displayed_monitors[i] && mp->monitors[i]) { /* We've just removed monitor<i> */ gtk_widget_destroy(mp->monitors[i]->da); monitor_free(mp->monitors[i]); mp->monitors[i] = NULL; } if (mp->monitors[i] && strncmp(mp->monitors[i]->color, colors[i], COLOR_SIZE) != 0) { /* We've changed the color */ monitor_set_foreground_color(mp, mp->monitors[i], colors[i]); } } /* Workaround meant to prevent users to display no monitor at all. * FIXME : write something clean. When there is only one monitor displayed, * its toggle button should not be clickable in the prefs. */ if (current_n_monitors == 0) { mp->displayed_monitors[0] = 1; goto start; } config_group_set_int(mp->settings, "DisplayCPU", mp->displayed_monitors[CPU_POSITION]); config_group_set_int(mp->settings, "DisplayRAM", mp->displayed_monitors[MEM_POSITION]); config_group_set_string(mp->settings, "Action", mp->action); config_group_set_string(mp->settings, "CPUColor", mp->monitors[CPU_POSITION] ? colors[CPU_POSITION] : NULL); config_group_set_string(mp->settings, "RAMColor", mp->monitors[MEM_POSITION] ? colors[MEM_POSITION] : NULL); RET(FALSE); }
/* Callback when panel configuration changes. */ static void wincmd_panel_reconfigure(LXPanel *panel, GtkWidget *p) { WinCmdPlugin * wc = lxpanel_plugin_get_data(p); lxpanel_button_set_icon(p, wc->image, panel_get_icon_size(panel)); }