static gboolean si_popup_show(gpointer icon) { GdkRectangle area; gint x, y; static gint count = 0; audgui_get_mouse_coords (NULL, & x, & y); gtk_status_icon_get_geometry (icon, NULL, & area, NULL); if (x < area.x || x > area.x + area.width || y < area.y || y > area.y + area.width) { si_popup_timer_stop(icon); si_popup_hide(icon); count = 0; return TRUE; } if (!POPUP_IS_ACTIVE) { if (count < 10) { count++; return TRUE; } else count = 0; audgui_infopopup_show_current(); g_object_set_data(G_OBJECT(icon), "popup_active", GINT_TO_POINTER(1)); } return TRUE; }
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); } }
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); } }
gboolean hippo_ui_get_pointer_position (HippoUI *ui, int *x_p, int *y_p) { GdkScreen *screen; GdkScreen *pointer_screen; int x, y; gtk_status_icon_get_geometry(GTK_STATUS_ICON(ui->icon), &screen, NULL, NULL); gdk_display_get_pointer(gdk_screen_get_display(screen), &pointer_screen, &x, &y, NULL); if (pointer_screen != screen) { x = 0; y = 0; } if (x_p) *x_p = x; if (y_p) *y_p = y; return pointer_screen == screen; }
//set up the popup menu, if enabled void set_menu(){ //TODO: add stock icons if (settings.enable_tray_menu){ GtkWidget *exit_entry = gtk_image_menu_item_new_with_mnemonic(_("_Exit")); GtkWidget *config_entry = gtk_image_menu_item_new_with_mnemonic(_("_Config Window")); GtkWidget *show_entry = gtk_image_menu_item_new_with_mnemonic(_("_Full Window")); GtkWidget *exit_icon = gtk_image_new_from_stock(GTK_STOCK_QUIT, GTK_ICON_SIZE_MENU); GtkWidget *config_icon = gtk_image_new_from_stock(GTK_STOCK_EXECUTE, GTK_ICON_SIZE_MENU); GtkWidget *show_icon = gtk_image_new_from_stock(GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_MENU); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(exit_entry), exit_icon); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(config_entry), config_icon); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(show_entry), show_icon); g_signal_connect(G_OBJECT(exit_entry), "activate", G_CALLBACK(gtk_main_quit), NULL); g_signal_connect(G_OBJECT(config_entry), "activate", G_CALLBACK(configure), NULL); g_signal_connect(G_OBJECT(show_entry), "activate", G_CALLBACK(open_window), NULL); if (G_IS_OBJECT(settings.tray_icon_menu)){ gtk_widget_destroy(settings.tray_icon_menu); } settings.tray_icon_menu = gtk_menu_new(); //Decide which order to stack the menu, so that the entry under the mouse //initially will hopefully be show_entry, which is what the user is most //likely trying to use, as opposed to exit_entry, which they probably do //not want to accidentally hit... GdkScreen *screen = gdk_screen_get_default(); int icon_x,icon_y; #if GTK_CHECK_VERSION(2,16,0) GdkScreen *screen_from_tray; GdkRectangle area; GtkOrientation orientation; if (gtk_status_icon_get_geometry(settings.tray_icon, &screen_from_tray, &area, &orientation)){ icon_x = area.x; icon_y = area.y; } else { icon_x = gdk_screen_get_width(screen); icon_y = gdk_screen_get_height(screen); } #else gtk_window_get_position(GTK_WINDOW(settings.tray_icon), &icon_x, &icon_y); #endif if (icon_y > gdk_screen_get_height(screen)/2){ //taskbar is on bottom, so put show_entry on bottom for ergonomics tray_at_bottom = true; gtk_menu_shell_append(GTK_MENU_SHELL(settings.tray_icon_menu), exit_entry); gtk_menu_shell_append(GTK_MENU_SHELL(settings.tray_icon_menu), config_entry); gtk_menu_shell_append(GTK_MENU_SHELL(settings.tray_icon_menu), show_entry); } else { //taskbar is on top, so put show_entry on top for ergonomics tray_at_bottom = false; gtk_menu_shell_append(GTK_MENU_SHELL(settings.tray_icon_menu), show_entry); gtk_menu_shell_append(GTK_MENU_SHELL(settings.tray_icon_menu), config_entry); gtk_menu_shell_append(GTK_MENU_SHELL(settings.tray_icon_menu), exit_entry); } //make menu potentially visible gtk_widget_show_all(settings.tray_icon_menu); } }
int gTrayIcon::height() { GdkRectangle area; if (!plug || !gtk_status_icon_get_geometry(plug, NULL, &area, NULL)) return 0; return area.height; }
static void cb_activate(GtkStatusIcon *status_icon, gpointer user_data) { // dbg("cb_activate\n"); toggle_im_enabled(); GdkRectangle rect; bzero(&rect, sizeof(rect)); GtkOrientation ori; gtk_status_icon_get_geometry(status_icon, NULL, &rect, &ori); }
static void move_win_kbm() { int width, height; get_win_size(gwin_kbm, &width, &height); int ox, oy; GdkRectangle r; GtkOrientation ori; #if UNIX int szx, szy; if (tray_da_win) { gdk_window_get_origin(tray_da_win, &ox, &oy); #if !GTK_CHECK_VERSION(2,91,0) gdk_drawable_get_size(tray_da_win, &szx, &szy); #else szx = gdk_window_get_width(tray_da_win); szy = gdk_window_get_height(tray_da_win); #endif if (oy<height) { oy = szy; } else { oy -= height; if (oy + height > dpy_yl) oy = dpy_yl - height; if (oy < 0) oy = szy; } if (ox + width > dpy_xl) ox = dpy_xl - width; if (ox < 0) ox = 0; } else #endif if (icon_main && gtk_status_icon_get_geometry(icon_main, NULL, &r, &ori)) { // dbg("rect %d:%d %d:%d\n", r.x, r.y, r.width, r.height); ox = r.x; if (ox + width > dpy_xl) ox = dpy_xl - width; if (r.y < 100) oy=r.y+r.height; else { oy = r.y - height; } } else { ox = dpy_xl - width; oy = dpy_yl - height - 31; } gtk_window_move(GTK_WINDOW(gwin_kbm), ox, oy); }
void hippo_ui_get_screen_info(HippoUI *ui, HippoRectangle *monitor_rect_p, HippoRectangle *tray_icon_rect_p, HippoOrientation *tray_icon_orientation_p) { GtkOrientation orientation; GdkScreen *screen; GdkRectangle icon_rect; GdkRectangle monitor; int monitor_num; gtk_status_icon_get_geometry(GTK_STATUS_ICON(ui->icon), &screen, &icon_rect, &orientation); if (monitor_rect_p) { HippoRectangle work_area; monitor_num = gdk_screen_get_monitor_at_point(screen, icon_rect.x + icon_rect.width / 2, icon_rect.y + icon_rect.height / 2); if (monitor_num < 0) monitor_num = 0; gdk_screen_get_monitor_geometry(screen, monitor_num, &monitor); monitor_rect_p->x = monitor.x; monitor_rect_p->y = monitor.y; monitor_rect_p->width = monitor.width; monitor_rect_p->height = monitor.height; screen_get_work_area(screen, &work_area); hippo_rectangle_intersect(monitor_rect_p, &work_area, monitor_rect_p); } if (tray_icon_rect_p) { tray_icon_rect_p->x = icon_rect.x; tray_icon_rect_p->y = icon_rect.y; tray_icon_rect_p->width = icon_rect.width; tray_icon_rect_p->height = icon_rect.height; } if (tray_icon_orientation_p) { if (orientation == GTK_ORIENTATION_VERTICAL) *tray_icon_orientation_p = HIPPO_ORIENTATION_VERTICAL; else *tray_icon_orientation_p = HIPPO_ORIENTATION_HORIZONTAL; } }
static VALUE si_get_geometry(VALUE self) { GdkScreen* screen; GdkRectangle area; GtkOrientation orientation; gboolean ret = gtk_status_icon_get_geometry(_SELF(self), &screen, &area, &orientation); if (ret) { return rb_ary_new3(3, GOBJ2RVAL(screen), BOXED2RVAL(&area, GDK_TYPE_RECTANGLE), GENUM2RVAL(orientation, GTK_TYPE_ORIENTATION)); } else { return rb_ary_new3(3, Qnil, Qnil, Qnil); } }
void show_notification(const gchar *summary, const gchar *message, const gchar *action, gint timeout, GCallback handler) { NotifyActionCallback callback; #ifndef HAVE_APP_INDICATOR GdkScreen *screen; GdkRectangle area; #endif /* HAVE_APP_INDICATOR */ if (notify_is_initted() == FALSE) return; if (notify) { g_signal_handlers_destroy(notify); notify_notification_close(notify, NULL); } notify = notify_notification_new(summary, message, ACTIVE_ICON_NAME); notify_notification_set_timeout(notify, timeout); #ifndef HAVE_APP_INDICATOR if (gtk_status_icon_get_visible(statusicon) == TRUE) { gtk_status_icon_get_geometry(statusicon, &screen, &area, NULL); notify_notification_set_hint_int32(notify, "x", area.x + area.width / 2); notify_notification_set_hint_int32(notify, "y", area.y + area.height / 2); } #endif /* HAVE_APP_INDICATOR */ notify_notification_set_urgency(notify, NOTIFY_URGENCY_NORMAL); callback = handler ? NOTIFY_ACTION_CALLBACK(handler) : notify_action; notify_notification_add_action(notify, "default", "action", callback, NULL, NULL); if (action != NULL) notify_notification_add_action(notify, "button", action, callback, NULL, NULL); notify_notification_show(notify, NULL); }
//callback that handles clicking the tray icon gboolean tray_button_press_event_callback (GObject *widget, GdkEventButton *event, GtkWidget *slider_window){ switch(event->button){ case 1: //left mouse button - toggle slider_window if (settings.tray_control){ if (GTK_WIDGET_VISIBLE(slider_window)){ gtk_widget_hide_all(slider_window); } else { int slider_width, slider_height, icon_width, icon_height, x_pos, y_pos; int tray_offset; //this may be needed if the tray border hides the bottom of the slider //get some dimensions gtk_window_get_size(GTK_WINDOW(slider_window), &slider_width, &slider_height); GdkScreen *screen = gdk_screen_get_default(); #if GTK_CHECK_VERSION(2,16,0) GdkScreen *screen_from_tray; GdkRectangle area; GtkOrientation orientation; if (gtk_status_icon_get_geometry(settings.tray_icon, &screen_from_tray, &area, &orientation)){ icon_width = area.width; icon_height = area.height; } else { //just outright guess icon_width = 24; icon_height = 24; } #else gtk_window_get_size(GTK_WINDOW(widget), &icon_width, &icon_height); #endif //compute the x position //x_pos = event->x_root - event->x - slider_width/2 + widget->allocation.width/2; x_pos = event->x_root - event->x - slider_width/2 + icon_width/2; //if the user has supplied an offset, use that, otherwise guess if (settings.tray_slider_offset >= 0){ tray_offset = settings.tray_slider_offset; } else { if (event->y_root > gdk_screen_get_height(screen)/2){ //tray at bottom tray_offset = gdk_screen_get_height(screen) - icon_height - event->y_root + event->y; } else { //tray at top tray_offset = event->y_root - event->y; } } //compute the y position if (event->y_root > gdk_screen_get_height(screen)/2){ //tray at bottom y_pos = event->y_root-event->y-slider_height-tray_offset; } else { //tray at top y_pos = icon_height+event->y_root-event->y+tray_offset; } //do the deed gtk_window_move(GTK_WINDOW(slider_window), x_pos, y_pos); gtk_widget_show_all(slider_window); } break; case 3: //right mouse button - display tray menu or main window, depending on settings.enable_tray_menu if (settings.enable_tray_menu){ gtk_menu_popup(GTK_MENU(settings.tray_icon_menu), NULL, NULL, NULL, NULL, event->button, event->time); } else { if (GTK_WIDGET_VISIBLE(settings.main_window)){ gtk_widget_hide(settings.main_window); } else { gtk_widget_show_all(settings.main_window); } } break; case 2: //middle mouse button - mute if (settings.tray_control && settings.tray_control->switch_id >= 0){ bool state = !(bool)list_ptr->elems[settings.tray_control->switch_id].get(); list_ptr->elems[settings.tray_control->switch_id].set((int)(state)); } break; default: break; } } update(NULL); return(true); }
//update the tray-icon and refresh the window gboolean update(gpointer data){ bool state = true; if (settings.enable_tray_icon){ if (settings.tray_control){ int val = settings.tray_control->get(); char tooltiptext[32]; if (settings.tray_control->switch_id >= 0){ state = (bool)list_ptr->elems[settings.tray_control->switch_id].get(); } if (state){ int image = 2+3*val/100; if (image > 4){ image=4; } else if (image < 0){ image=0; } else if (val == 0){ image=1; } sprintf(tooltiptext, _("Volume: %d%%"), val); #if GTK_CHECK_VERSION(2,16,0) gtk_status_icon_set_from_file(settings.tray_icon, settings.icon_file_names[image]); #else gtk_image_set_from_file(GTK_IMAGE(settings.tray_icon_image), settings.icon_file_names[image]); #endif } else { sprintf(tooltiptext, _("Volume: Muted")); #if GTK_CHECK_VERSION(2,16,0) gtk_status_icon_set_from_file(settings.tray_icon, settings.icon_file_names[0]); #else gtk_image_set_from_file(GTK_IMAGE(settings.tray_icon_image), settings.icon_file_names[0]); #endif } #if GTK_CHECK_VERSION(2,16,0) gtk_status_icon_set_tooltip_text(settings.tray_icon, tooltiptext); #elif GTK_CHECK_VERSION(2,12,0) gtk_widget_set_tooltip_text(settings.tray_icon_image, tooltiptext); #else static GtkTooltips *tooltips = gtk_tooltips_new(); gtk_tooltips_set_tip(tooltips, settings.tray_icon_image, tooltiptext, NULL); #endif //if the tray was moved, update the menu GdkScreen *screen = gdk_screen_get_default(); int icon_x,icon_y; #if GTK_CHECK_VERSION(2,16,0) GdkScreen *screen_from_tray; GdkRectangle area; GtkOrientation orientation; if (gtk_status_icon_get_geometry(settings.tray_icon, &screen_from_tray, &area, &orientation)){ icon_x = area.x; icon_y = area.y; } else { icon_x = gdk_screen_get_width(screen); icon_y = gdk_screen_get_height(screen); } #else gtk_window_get_position(GTK_WINDOW(settings.tray_icon), &icon_x, &icon_y); #endif if ((bool)(icon_y > gdk_screen_get_height(screen)/2) ^ tray_at_bottom){ //the current status does not match the previous status, so update the menu set_menu(); } //in case the icon was hidden due to the tray exiting, try reshowing it again #if GTK_CHECK_VERSION(2,16,0) gtk_status_icon_set_visible(settings.tray_icon, true); #else gtk_widget_show_all(settings.tray_icon); #endif } } if (GTK_WIDGET_VISIBLE(settings.main_window)){ gtk_widget_queue_draw(settings.main_window); } if (GTK_WIDGET_VISIBLE(settings.slider_window)){ gtk_widget_queue_draw(settings.slider_window); } return(true); }
static void create_win_message(char *icon, char *text, int duration) { GtkWidget *gwin_message = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_has_resize_grip(GTK_WINDOW(gwin_message), FALSE); gtk_container_set_border_width (GTK_CONTAINER (gwin_message), 0); gtk_widget_realize (gwin_message); GdkWindow *gdkwin = gtk_widget_get_window(gwin_message); set_no_focus(gwin_message); GtkWidget *hbox = gtk_hbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (gwin_message), hbox); if (icon[0] != '-') { GtkWidget *image = gtk_image_new_from_file(icon); if (text[0] == '-') { #if GTK_CHECK_VERSION(2,91,0) GdkPixbuf *pixbuf = NULL; GdkPixbufAnimation *anime = NULL; switch(gtk_image_get_storage_type(GTK_IMAGE(image))) { case GTK_IMAGE_PIXBUF: pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image)); break; case GTK_IMAGE_ANIMATION: anime = gtk_image_get_animation(GTK_IMAGE(image)); pixbuf = gdk_pixbuf_animation_get_static_image(anime); break; default: break; } cairo_surface_t *img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf)); cairo_t *cr = cairo_create(img); gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0); cairo_paint(cr); cairo_region_t *mask = gdk_cairo_region_create_from_surface(img); gtk_widget_shape_combine_region(gwin_message, mask); cairo_region_destroy(mask); cairo_destroy(cr); cairo_surface_destroy(img); #else GdkBitmap *bitmap = NULL; gdk_pixbuf_render_pixmap_and_mask(gdk_pixbuf_new_from_file(icon, NULL), NULL, &bitmap, 128); gtk_widget_shape_combine_mask(gwin_message, bitmap, 0, 0); #endif } gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); } if (text[0] != '-') { GtkWidget *label = gtk_label_new(text); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); } gtk_widget_show_all(gwin_message); int width, height; get_win_size(gwin_message, &width, &height); int ox=-1, oy; int szx, szy; if (tray_da_win) { gdk_window_get_origin (tray_da_win, &ox, &oy); #if !GTK_CHECK_VERSION(2,91,0) gdk_drawable_get_size(tray_da_win, &szx, &szy); #else szx = gdk_window_get_width(tray_da_win); szy = gdk_window_get_height(tray_da_win); #endif if (oy<height) { oy = szy; } else { oy -= height; if (oy + height > dpy_yl) oy = dpy_yl - height; if (oy < 0) oy = 0; } if (ox + width > dpy_xl) ox = dpy_xl - width; if (ox < 0) ox = 0; } else if (icon_main) { GdkRectangle rect; GtkOrientation ori; if (gtk_status_icon_get_geometry(icon_main, NULL, &rect, &ori)) { dbg("rect %d,%d\n", rect.x, rect.y, rect.width, rect.height); if (ori==GTK_ORIENTATION_HORIZONTAL) { ox=rect.x; if (rect.y > 100) oy=rect.y - height; else oy=rect.y + rect.height; } else { oy=rect.y; if (rect.x > 100) ox=rect.x - width; else ox=rect.x + rect.width; } } } if (ox < 0) { ox = dpy_xl - width; oy = dpy_yl - height; } gtk_window_move(GTK_WINDOW(gwin_message), ox, oy); g_timeout_add(duration, (GSourceFunc)timeout_destroy_window, gwin_message); }