]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-ui-utils.c
Merge branch 'people-nearby-fake-group-613558'
[empathy.git] / libempathy-gtk / empathy-ui-utils.c
index d6e9ffeef37ff7701b8783b7b06184da509173e9..d4de211c08f1337d5663c0952efc1862e2fb838b 100644 (file)
@@ -1373,7 +1373,8 @@ empathy_window_iconify (GtkWindow *window, GtkStatusIcon *status_icon)
 
        XChangeProperty (dpy,
                         GDK_WINDOW_XID (gdk_window),
-                        gdk_x11_get_xatom_by_name_for_display (gdk_drawable_get_display (gdk_window),
+                        gdk_x11_get_xatom_by_name_for_display (
+                               gdk_drawable_get_display (gdk_window),
                         "_NET_WM_ICON_GEOMETRY"),
                         XA_CARDINAL, 32, PropModeReplace,
                         (guchar *)&data, 4);
@@ -1382,13 +1383,61 @@ empathy_window_iconify (GtkWindow *window, GtkStatusIcon *status_icon)
        gtk_window_iconify (window);
 }
 
+/* Code from Thomas Thurman
+ * http://people.collabora.co.uk/~tthurman/pingwindow.c.txt
+ */
+static guint32
+get_server_time (void)
+{
+  Display *display;
+  Window pingingWindow;
+  XEvent propertyEvent;
+  XSetWindowAttributes attrs;
+
+  display = XOpenDisplay (NULL);
+
+  attrs.override_redirect = True;
+  attrs.event_mask = PropertyChangeMask;
+
+  pingingWindow = XCreateWindow (display,
+      XRootWindow (display, 0), /* parent */
+      -100, -100, 1, 1, /* off-screen */
+      0,
+      CopyFromParent,
+      CopyFromParent,
+      (Visual *) CopyFromParent,
+      CWOverrideRedirect | CWEventMask,
+      &attrs);
+
+  /* Change a property. XA_PRIMARY is never really
+   * used for properties, so it's safe.
+   */
+  XChangeProperty (display,
+      pingingWindow,
+      XA_PRIMARY, XA_STRING, 8,
+      PropModeAppend, NULL, 0);
+
+  /* Pick up the event. */
+  XWindowEvent (display,
+      pingingWindow,
+      PropertyChangeMask,
+      &propertyEvent);
+
+  /* If you want to do this often,
+   * just keep the window around and
+   * don't destroy it.
+   */
+  XDestroyWindow (display, pingingWindow);
+
+  return ((XPropertyEvent *) &propertyEvent)->time;
+}
+
 /* Takes care of moving the window to the current workspace. */
 void
-empathy_window_present (GtkWindow *window,
-                       gboolean   steal_focus)
+empathy_window_present (GtkWindow *window)
 {
-       guint32 timestamp;
        GdkWindow *gdk_window;
+       guint32 timestamp;
 
        g_return_if_fail (GTK_IS_WINDOW (window));
 
@@ -1411,6 +1460,10 @@ empathy_window_present (GtkWindow *window,
        }
 
        timestamp = gtk_get_current_event_time ();
+       if (timestamp == 0)
+               /* No event, fallback to X server time */
+               timestamp = get_server_time ();
+
        gtk_window_present_with_time (window, timestamp);
        gtk_window_set_skip_taskbar_hint (window, FALSE);
        gtk_window_deiconify (window);
@@ -1632,6 +1685,9 @@ empathy_send_file_with_file_chooser (EmpathyContact *contact)
 
        gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (widget), FALSE);
 
+       gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (widget),
+               g_get_home_dir ());
+
        g_signal_connect (widget, "response",
                          G_CALLBACK (file_manager_send_file_response_cb),
                          contact);
@@ -1670,6 +1726,7 @@ void
 empathy_receive_file_with_file_chooser (EmpathyFTHandler *handler)
 {
        GtkWidget *widget;
+       const gchar *dir;
 
        widget = gtk_file_chooser_dialog_new (_("Select a destination"),
                                              NULL,
@@ -1684,6 +1741,13 @@ empathy_receive_file_with_file_chooser (EmpathyFTHandler *handler)
        gtk_file_chooser_set_do_overwrite_confirmation
                (GTK_FILE_CHOOSER (widget), TRUE);
 
+       dir = g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD);
+       if (dir == NULL)
+               /* Fallback to $HOME if $XDG_DOWNLOAD_DIR is not set */
+               dir = g_get_home_dir ();
+
+       gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (widget), dir);
+
        g_signal_connect (widget, "response",
                G_CALLBACK (file_manager_receive_file_response_cb), handler);