Changeset 4932


Ignore:
Timestamp:
Feb 7, 2008, 1:10:34 AM (14 years ago)
Author:
charles
Message:

(gtk) #686: "Minimize to tray"

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/main.c

    r4912 r4932  
    3535#include <glib/gi18n.h>
    3636#include <glib/gstdio.h>
     37
     38#include <gdk/gdk.h>
     39#ifdef GDK_WINDOWING_X11
     40#include <X11/Xatom.h>
     41#include <gdk/gdkx.h>
     42#endif
    3743
    3844#include "actions.h"
     
    99105struct cbdata
    100106{
     107    guint          idle_hide_mainwindow_tag;
    101108    GtkWindow    * wind;
    102109    TrCore       * core;
    103     GtkWidget    * icon;
     110    gpointer      icon;
    104111    GtkWidget    * msgwin;
    105112    GtkWidget    * prefs;
     
    377384
    378385    /* show the window */
    379     if( minimized )
     386    if( minimized ) {
    380387        gtk_window_iconify( wind );
     388        gtk_window_set_skip_taskbar_hint( cbdata->wind, cbdata->icon != NULL );
     389    }
    381390    gtk_widget_show( GTK_WIDGET( wind ) );
    382391}
    383392
    384 static void
    385 setMainWindowMinimized( struct cbdata * data, gboolean minimized )
    386 {
    387     GtkWindow * window = GTK_WINDOW( data->wind );
    388 
    389     if(( data->minimized = minimized ))
    390         gtk_window_iconify( window );
     393
     394/**
     395 * hideMainWindow, and the timeout hack in toggleMainWindow,
     396 * are loosely cribbed from Colin Walters' tr-shell.c in Rhythmbox
     397 */
     398static gboolean
     399idle_hide_mainwindow( gpointer window )
     400{
     401    gtk_widget_hide( window );
     402    return FALSE;
     403}
     404static void
     405hideMainWindow( struct cbdata * cbdata )
     406{
     407#if defined(STATUS_ICON_SUPPORTED) && defined(GDK_WINDOWING_X11)
     408    GdkRectangle  bounds;
     409    gulong        data[4];
     410    Display      *dpy;
     411    GdkWindow    *gdk_window;
     412
     413    gtk_status_icon_get_geometry( GTK_STATUS_ICON( cbdata->icon ), NULL, &bounds, NULL );
     414    gdk_window = GTK_WIDGET (cbdata->wind)->window;
     415    dpy = gdk_x11_drawable_get_xdisplay (gdk_window);
     416
     417    data[0] = bounds.x;
     418    data[1] = bounds.y;
     419    data[2] = bounds.width;
     420    data[3] = bounds.height;
     421
     422    XChangeProperty (dpy,
     423                     GDK_WINDOW_XID (gdk_window),
     424                     gdk_x11_get_xatom_by_name_for_display (gdk_drawable_get_display (gdk_window),
     425                     "_NET_WM_ICON_GEOMETRY"),
     426                     XA_CARDINAL, 32, PropModeReplace,
     427                     (guchar*)&data, 4);
     428
     429    gtk_window_set_skip_taskbar_hint( cbdata->wind, TRUE );
     430#endif
     431    gtk_window_iconify( cbdata->wind );
     432}
     433
     434static void
     435clearTag( guint * tag )
     436{
     437    if( *tag )
     438        g_source_remove( *tag );
     439    *tag = 0;
     440}
     441
     442static void
     443toggleMainWindow( struct cbdata * cbdata )
     444{
     445    GtkWindow * window = GTK_WINDOW( cbdata->wind );
     446    const int hide = cbdata->minimized = !cbdata->minimized;
     447
     448    if( hide )
     449    {
     450        clearTag( &cbdata->idle_hide_mainwindow_tag );
     451        hideMainWindow( cbdata );
     452        cbdata->idle_hide_mainwindow_tag = g_timeout_add( 250, idle_hide_mainwindow, window );
     453    }
    391454    else
     455    {
     456        gtk_window_set_skip_taskbar_hint( window, FALSE );
     457        gtk_widget_show( GTK_WIDGET( window ) );
    392458        gtk_window_deiconify( window );
    393 }
    394 
    395 static void
    396 toggleMainWindow( struct cbdata * data )
    397 {
    398     setMainWindowMinimized( data, !data->minimized );
     459        gtk_window_present_with_time( window, gtk_get_current_event_time( ) );
     460    }
    399461}
    400462
     
    405467
    406468    if( cbdata->icon != NULL )
    407         setMainWindowMinimized( cbdata, TRUE );
     469        action_activate ("toggle-main-window");
    408470    else
    409471        askquit( cbdata->core, cbdata->wind, wannaquit, cbdata );
Note: See TracChangeset for help on using the changeset viewer.