[PATCH] Panel Clock Improvements: I18N tooltip, calender popup

Oliver M. Bolzer oliver at fakeroot.net
Fri Dec 5 15:02:46 CET 2003


Hi!

On Thu, Dec 04, 2003 at 04:19:33PM +0100, Mickael Graf <mgf at bredband.net> wrote...

> >I'm not sure. I was thinking about running xfcalendar from the clock.
> >That would give you additional appointments.
 
> Left-Click on the clock to launch xfcalendar w/ or w/o borders sounds 
> nice, and left-click again on the clock close it.
> 
> There's two way for doing this:
> 
> - integrate codes from xfcalendar and clock into one
> - launch xfcalendar as a separate application

Running away from tons of other stuff I should be doing, I tried to take
the good of both ways. The attached patches to the clock plugin and xfcalender
implement the following when the clock is clicked. This is intended as demonstration
for one possible behaviour.

- Do nothing if xfcalender is not already running
- If xfcalender is running and calender is visible, hide it (like clicking on
  tray icon)
- If xfcalender is running and calender is hidden, show it close to the clock

The positioning of the popoup is imperfect in certain cases (panel in lower
screen half in horizontal mode and panel in right half in vertical mode),
because the panel would need the calender's size to calculate that correctly.

>From the perspective of a user, the clock-xfcalender interaction could look
like this

- clock has a built-in calender. Dead simple, something like the patch
  I sent before
- configuration option of clock "Display xfcalender instead of built-in calender"
- if option selected, clock launches xfcalender if not already running and does what
  this patch does 

What do you think?

-- 
	Oliver M. Bolzer

GPG (PGP) Fingerprint = 621B 52F6 2AC1 36DB 8761  018F 8786 87AD EF50 D1FF
-------------- next part --------------
RCS file: /cvsroot/xfce/xfce4/xfcalendar/src/main.c,v
retrieving revision 1.23
diff -u -r1.23 main.c
--- src/main.c	14 Nov 2003 15:28:25 -0000	1.23
+++ src/main.c	5 Dec 2003 13:31:27 -0000
@@ -104,6 +104,18 @@
       gdk_window_raise(mainWindow->window);
       gdk_window_focus(mainWindow->window, GDK_CURRENT_TIME);
       return(GDK_FILTER_REMOVE);
+    } else if (xev->message_type == XInternAtom(GDK_DISPLAY(),
+                                                "_XFCE_CALENDAR_TOGGLE_HERE", False)) {
+      /* check correct format */
+      if (xev->format == 32) {
+          int x, y;
+          x = xev->data.l[0];
+          y = xev->data.l[1];
+          g_print("TOGGLE HERE...., x: %i, y: %i\n", x, y );
+          gtk_window_move( GTK_WINDOW(mainWindow), x, y );
+          toggle_visible_cb( mainWindow );
+      }
+      return(GDK_FILTER_REMOVE);
     }
     break;
   }
-------------- next part --------------
RCS file: /cvsroot/xfce/xfce4/xfce4-panel/plugins/clock/clock.c,v
retrieving revision 1.25
diff -u -r1.25 clock.c
--- plugins/clock/clock.c	4 Dec 2003 08:26:39 -0000	1.25
+++ plugins/clock/clock.c	5 Dec 2003 13:30:39 -0000
@@ -1,4 +1,5 @@
-/*  clock.c
+/*  int width, height;
+ *  clock.c
  *
  *  Copyright (C) 2002 Jasper Huijsmans(huysmans at users.sourceforge.net)
  *                     Xavier Maillard (zedek at fxgsproject.org)
@@ -59,6 +60,7 @@
     GtkWidget *eventbox;
     GtkWidget *clock;		/* our XfceClock widget */
 
+    int orientation;            /* panel orientation */
     int timeout_id;		/* update the date tooltip */
 }
 t_clock;
@@ -88,7 +90,52 @@
 }
 ClockDialog;
 
-#include <langinfo.h>
+void
+calculate_calendar_position( GtkWidget *parent, int orientation,
+                             int *cal_x, int *cal_y );
+/* click callback */
+static gboolean
+on_button_press_event_cb(GtkWidget *widget,
+                         GdkEventButton *event, gpointer data)
+{
+  GdkAtom atom;
+  Window xwindow;
+  int width, height;
+
+  if (event->button == 1)
+  {
+      t_clock *clock;
+
+      if (data == NULL)
+          return FALSE;
+
+      clock = (t_clock*)data;
+
+      /** send message to xfcalendar if it is running */
+      atom = gdk_atom_intern("_XFCE_CALENDAR_RUNNING", FALSE);
+      if ((xwindow = XGetSelectionOwner(GDK_DISPLAY(),
+                                        gdk_x11_atom_to_xatom(atom))) != None)
+      {
+          XClientMessageEvent xev;
+          int x, y = 0;
+
+          calculate_calendar_position( clock->eventbox, clock->orientation, &x, &y );
+          memset(&xev, 0, sizeof(xev));
+          xev.type = ClientMessage;
+          xev.window = xwindow;
+          xev.message_type = XInternAtom(GDK_DISPLAY(), "_XFCE_CALENDAR_TOGGLE_HERE", FALSE);
+          xev.format = 32;
+          xev.data.l[0] = x;
+          xev.data.l[1] = y;
+          XSendEvent(GDK_DISPLAY(), xwindow, False, NoEventMask, (XEvent *)&xev);
+          XSync(GDK_DISPLAY(), False);
+
+          return TRUE;
+      }        
+  }
+  return FALSE;
+}
+
 /* creation and destruction */
 gboolean
 clock_date_tooltip (GtkWidget * widget)
@@ -152,6 +199,11 @@
 	g_timeout_add (60000, (GSourceFunc) clock_date_tooltip,
 		       clock->eventbox);
 
+    /* callback for calendar popup */
+    g_signal_connect(G_OBJECT(clock->eventbox), "button-press-event",
+                     G_CALLBACK(on_button_press_event_cb), clock);
+
+    clock->orientation = GTK_ORIENTATION_HORIZONTAL;
     return clock;
 }
 
@@ -217,6 +269,13 @@
     update_clock_size (tmp, size);
 }
 
+void
+clock_set_orientation(Control *control, int orientation)
+{
+    t_clock *clock = (t_clock*)control->data;
+    clock->orientation = orientation;
+}
+
 /* Write the configuration at exit */
 void
 clock_write_config (Control * control, xmlNodePtr parent)
@@ -578,6 +637,73 @@
     return TRUE;
 }
 
+/* calculate position of calendar popup */
+void
+calculate_calendar_position( GtkWidget *parent, int orientation, int *cal_x, int *cal_y )
+{
+  gint parent_x, parent_y, parent_w, parent_h;  /* parent position */
+  gint root_w, root_h;  /* desktop size */
+  gint x, y;  /* window position and size */
+  
+  /** positioning code adopted from Choe Hwanjin's datetime-plugin **/
+  /* obtain parent's and desktop size */
+  gdk_window_get_origin(GDK_WINDOW(parent->window), &parent_x, &parent_y);
+  gdk_drawable_get_size(GDK_DRAWABLE(parent->window), &parent_w, &parent_h);
+      
+  root_w = gdk_screen_width();
+  root_h = gdk_screen_height();
+    
+  if (orientation == GTK_ORIENTATION_VERTICAL) {
+      if (parent_x < root_w / 2) {
+          if (parent_y < root_h / 2) {
+              /* upper left */
+              x = parent_x + parent_w;
+              y = parent_y;
+          } else {
+              /* lower left */
+              x = parent_x + parent_w;
+              y = parent_y + parent_h;
+          }
+      } else {
+          if (parent_y < root_h / 2) {
+              /* upper right */
+              x = parent_x;
+              y = parent_y;
+          } else {
+              /* lower right */
+              x = parent_x;
+              y = parent_y + parent_h;
+          }
+      }
+  } else {   /* HORIZONTAL */
+      if (parent_x < root_w / 2) {
+          if (parent_y < root_h / 2) {
+              /* upper left */
+              x = parent_x;
+              y = parent_y + parent_h;
+          } else {
+              /* lower left */
+              x = parent_x + parent_w;
+              y = parent_y;
+          }
+      } else {
+          if (parent_y < root_h / 2) {
+              /* upper right */
+              x = parent_x + parent_w;
+              y = parent_y + parent_h;
+          } else {
+             /* lower right */
+             x = parent_x + parent_w;
+             y = parent_y;
+          }
+      }
+  }
+  *cal_x = x;
+  *cal_y = y;
+}
+
+
+
 G_MODULE_EXPORT void
 xfce_control_class_init (ControlClass * cc)
 {
@@ -594,6 +720,7 @@
     cc->create_options = clock_create_options;
 
     cc->set_size = clock_set_size;
+    cc->set_orientation = clock_set_orientation;
 }
 
 /* macro defined in plugins.h */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://mail.xfce.org/pipermail/xfce4-dev/attachments/20031205/3d3226ea/attachment.pgp>


More information about the Xfce4-dev mailing list