[Fedora-directory-commits] esc/src/lib/notifytray config.mk, NONE, 1.1 Makefile, NONE, 1.1 manifest.mn, NONE, 1.1 notifyareaicon.c, NONE, 1.1 notifyareaicon.h, NONE, 1.1 notify.def, NONE, 1.1 notifytray.c, NONE, 1.1 notifytray.h, NONE, 1.1

Jack Magne (jmagne) fedora-directory-commits at redhat.com
Wed Sep 13 18:06:11 UTC 2006


Author: jmagne

Update of /cvs/dirsec/esc/src/lib/notifytray
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv16017

Added Files:
	config.mk Makefile manifest.mn notifyareaicon.c 
	notifyareaicon.h notify.def notifytray.c notifytray.h 
Log Message:
Initial revision.



--- NEW FILE config.mk ---
# ***** BEGIN COPYRIGHT BLOCK *****
# This Program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; version 2 of the License.
#
# This Program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
#
# Copyright (C) 2005 Red Hat, Inc.
# All rights reserved.
# ***** END COPYRIGHT BLOCK *****

TARGETS        = $(LIBRARY)
#SHARED_LIBRARY =
#IMPORT_LIBRARY =
#PROGRAM        =



--- NEW FILE Makefile ---
#! gmake
#
# BEGIN COPYRIGHT BLOCK
# This Program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; version 2 of the License.
#
# This Program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
#
# Copyright (C) 2005 Red Hat, Inc.
# All rights reserved.
# END COPYRIGHT BLOCK

#######################################################################
# (1) Include initial platform-independent assignments (MANDATORY).   #
#######################################################################

include manifest.mn

#######################################################################
# (2) Include "global" configuration information. (OPTIONAL)          #
#######################################################################

include $(CORE_DEPTH)/coreconf/config.mk

#######################################################################
# (3) Include "component" configuration information. (OPTIONAL)       #
#######################################################################

DEFINES += -DDLL_PREFIX=\"$(DLL_PREFIX)\"
DEFINES += -DDLL_SUFFIX=\"$(DLL_SUFFIX)\"


#######################################################################
# (4) Include "local" platform-dependent assignments (OPTIONAL).      #
#######################################################################

include config.mk

ifeq ($(HAVE_LIB_NOTIFY),1)
CFLAGS += -DHAVE_LIB_NOTIFY
endif

#######################################################################
# (5) Execute "global" rules. (OPTIONAL)                              #
#######################################################################

include $(CORE_DEPTH)/coreconf/rules.mk

#######################################################################
# (6) Execute "component" rules. (OPTIONAL)                           #
#######################################################################



#######################################################################
# (7) Execute "local" rules. (OPTIONAL).                              #
#######################################################################

pig:
	echo "HAVE_LIB_NOTIFY" $(HAVE_LIB_NOTIFY)
	echo "CFLAGS" + $(CFLAGS)


--- NEW FILE manifest.mn ---
# BEGIN COPYRIGHT BLOCK
# This Program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; version 2 of the License.
#
# This Program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
#
# Copyright (C) 2005 Red Hat, Inc.
# All rights reserved.
# END COPYRIGHT BLOCK

CORE_DEPTH	= ../../..

DEFINES += $(shell pkg-config --cflags gtk+-2.0)
CCFLAGS += $(shell pkg-config --libs gtk+-2.0) 
CCFLAGS += $(shell pkg-config --cflags glib-2.0)

ifeq ($(HAVE_LIB_NOTIFY),1)
LDFLAGS += $(shell pkg-config --libs libnotify)
REQUIRES = libnotify
endif

MODULE		= traynotify
LIBRARY_NAME	= $(MODULE)
MAPFILE 	= $(OBJDIR)/notify.def

CSRCS		= \
		notifytray.c \
		notifyareaicon.c \
		$(NULL)

EXPORTS 	= \
		notifytray.h \
		$(NULL)



--- NEW FILE notifyareaicon.c ---
/** BEGIN COPYRIGHT BLOCK
 * This Program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; version 2 of the License.
 *
 * This Program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA.
 *
 * Copyright (C) 2005 Red Hat, Inc.
 * All rights reserved.
 * END COPYRIGHT BLOCK **/

#include <string.h>
#include <gdk/gdkx.h>
#include "notifyareaicon.h"

#define SYSTEM_TRAY_REQUEST_DOCK    0
#define SYSTEM_TRAY_BEGIN_MESSAGE   1
#define SYSTEM_TRAY_CANCEL_MESSAGE  2
         
static void notify_area_icon_class_init(NotifyAreaIconClass *theClass);
static void notify_area_icon_init(NotifyAreaIcon *icon);
static void notify_area_icon_unrealize (GtkWidget *widget);

static void notify_area_icon_update_manager_wnd (NotifyAreaIcon *icon);

static GtkPlugClass *plug_parent_class  = NULL;

GType
notify_area_icon_get_type (void)
{
  static GType my_type = 0;

  my_type = g_type_from_name("CoolKeyTrayIcon");

  if (my_type == 0)
    {
      static const GTypeInfo my_info =
      {
        sizeof (NotifyAreaIconClass),
        (GBaseInitFunc) NULL,
        (GBaseFinalizeFunc) NULL,
        (GClassInitFunc) notify_area_icon_class_init,
        NULL, /* class_finalize */
        NULL, /* class_data */
        sizeof (NotifyAreaIcon),
        0,    /* n_preallocs */
        (GInstanceInitFunc) notify_area_icon_init
      };

      my_type = g_type_register_static (GTK_TYPE_PLUG, "CoolKeyTrayIcon", &my_info,(GTypeFlags) 0);
    }
  else 
  {
      if (plug_parent_class == NULL) {
          notify_area_icon_class_init((NotifyAreaIconClass *)g_type_class_peek(my_type));
      }
  }

  return my_type;
}


static void
notify_area_icon_init (NotifyAreaIcon *icon)
{
  icon->counter = 1;
  
  gtk_widget_add_events (GTK_WIDGET (icon), GDK_PROPERTY_CHANGE_MASK);
}

static void
notify_area_icon_class_init (NotifyAreaIconClass *theClass)
{
  GtkWidgetClass *widget_klass = (GtkWidgetClass *)theClass;

  plug_parent_class =  (GtkPlugClass *) g_type_class_peek_parent (theClass);

  widget_klass->unrealize = notify_area_icon_unrealize;

}


static void
notify_area_icon_unrealize (GtkWidget *widget)
{
  NotifyAreaIcon *icon =  (NotifyAreaIcon *) widget;

  GdkWindow *root_window;

  g_print("notify_area_icon_unrealize \n");
  if (icon->manager_wnd != None)
    {
      GdkWindow *gdkwin;
      gdkwin = gdk_window_lookup (icon->manager_wnd);

    }

  root_window = gdk_window_lookup (gdk_x11_get_default_root_xwindow ());

  if (GTK_WIDGET_CLASS (plug_parent_class)->unrealize)
    (* GTK_WIDGET_CLASS (plug_parent_class)->unrealize) (widget);
}

static void
notify_area_icon_send_manager_msg (NotifyAreaIcon *icon,
				    long         message,
				    Window       window,
				    long         data1,
				    long         data2,
				    long         data3)
{
  XClientMessageEvent ev;
  Display *display;
 
  g_print("notify_area_icon_send_manager_msg \n");
 
  ev.type = ClientMessage;
  ev.window = window;
  ev.message_type = icon->system_tray_opcode_atom;
  ev.format = 32;
  ev.data.l[0] = gdk_x11_get_server_time (GTK_WIDGET (icon)->window);
  ev.data.l[1] = message;
  ev.data.l[2] = data1;
  ev.data.l[3] = data2;
  ev.data.l[4] = data3;

  display = gdk_display;
  
  gdk_error_trap_push ();
  XSendEvent (display,
	      icon->manager_wnd, False, NoEventMask, (XEvent *)&ev);
  XSync (display, False);
  gdk_error_trap_pop ();
}

static void
notify_area_icon_send_dock_request (NotifyAreaIcon *icon)
{

    g_print("notify_area_icon_send_dock_request \n");
    notify_area_icon_send_manager_msg (icon,
				      SYSTEM_TRAY_REQUEST_DOCK,
				      icon->manager_wnd,
				      gtk_plug_get_id (GTK_PLUG (icon)),
				      0, 0);
}

static void
notify_area_icon_update_manager_wnd(NotifyAreaIcon *icon)
{
  Display *xdisplay;
 
  xdisplay = gdk_display;
  
  if (icon->manager_wnd != None)
    {
      GdkWindow *gdkwin;

      gdkwin = gdk_window_lookup (icon->manager_wnd);
      
    }
  
  XGrabServer (xdisplay);
  
  icon->manager_wnd = XGetSelectionOwner (xdisplay, icon->selection_atom);

  if (icon->manager_wnd != None)
    XSelectInput (xdisplay,
		  icon->manager_wnd, StructureNotifyMask);

  XUngrabServer (xdisplay);
  XFlush (xdisplay);
  
  if (icon->manager_wnd != None)
    {
      GdkWindow *gdkwin;

      gdkwin = gdk_window_lookup (icon->manager_wnd);
     
     g_print("update_manager_wnd gdkwin %p \n",gdkwin); 

      /* Send dock request */
      notify_area_icon_send_dock_request (icon);
    }

}

NotifyAreaIcon *
notify_area_icon_new(const gchar *name)
{
  NotifyAreaIcon *icon;
  char buff[256];
  GdkWindow *root;

  Screen *xscreen = DefaultScreenOfDisplay (gdk_display);

  g_return_val_if_fail (xscreen != NULL,NULL);

  g_print("notify_area_icon_new_for_xscreen \n");

  icon = (NotifyAreaIcon *) g_object_new(notify_area_icon_get_type ()
, NULL);

  gtk_window_set_title (GTK_WINDOW (icon), name);

  gtk_plug_construct (GTK_PLUG (icon), 0);  
  
  gtk_widget_realize (GTK_WIDGET (icon)); 

  g_snprintf (buff, sizeof (buff),
	      "_NET_SYSTEM_TRAY_S%d",
	      XScreenNumberOfScreen (xscreen));
  
  icon->selection_atom = XInternAtom (DisplayOfScreen (xscreen),
				      buff, False);
  
  icon->system_tray_opcode_atom = XInternAtom (DisplayOfScreen (xscreen),
					       "_NET_SYSTEM_TRAY_OPCODE", False);

  notify_area_icon_update_manager_wnd(icon); 

  root = gdk_window_lookup (gdk_x11_get_default_root_xwindow ());
 
  icon->tooltips = gtk_tooltips_new ();

  return icon;
}

guint
notify_area_icon_send_msg (NotifyAreaIcon *icon,
			    gint         timeout,
			    const char *message,
			    gint         msg_len)
{
  guint counter;
 
  g_print("notify_area_tray_icon_send_msg \n"); 
  g_return_val_if_fail (timeout >= 0, 0);
  g_return_val_if_fail (message != NULL, 0);
		     
  if (icon->manager_wnd == None)
    return 0;

  int len = strlen(message);

  counter = icon->counter++;
  
  notify_area_icon_send_manager_msg (icon, SYSTEM_TRAY_BEGIN_MESSAGE,
				      (Window)gtk_plug_get_id (GTK_PLUG (icon)),
				      timeout, len, counter);

  int message_chunk_size = 20;

  gdk_error_trap_push ();

  /* Send the message in chunks  of 20*/

  while (len > 0)
  {
      XClientMessageEvent ev;
      Display *xdisplay;

     
      xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon))); 
      ev.type = ClientMessage;
      ev.window = (Window)gtk_plug_get_id (GTK_PLUG (icon));
      ev.format = 8;
      ev.message_type = XInternAtom (xdisplay,
				     "_NET_SYSTEM_TRAY_MESSAGE_DATA", False);
      if (len > message_chunk_size) 
	{
	  memcpy ((char *)&ev.data, message, message_chunk_size);
	  len -= message_chunk_size;
	  message += message_chunk_size;
	}
      else
	{
	  memcpy ((char *)&ev.data, message, len);
	  len = 0;
	}

      XSendEvent (xdisplay,
		  icon->manager_wnd, False, StructureNotifyMask, (XEvent *)&ev);
      XSync (xdisplay, False);
  }
  gdk_error_trap_pop ();

  return counter;
}


--- NEW FILE notifyareaicon.h ---
/** BEGIN COPYRIGHT BLOCK
 * This Program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; version 2 of the License.
 *
 * This Program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA.
 *
 * Copyright (C) 2005 Red Hat, Inc.
 * All rights reserved.
 * END COPYRIGHT BLOCK **/

#ifndef _NOTIFY_AREA_ICON_H
#define _NOTIFY_AREA_ICON_H

#include <gtk/gtkplug.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>

G_BEGIN_DECLS
	
struct _NotifyAreaIcon
{

  GtkPlug parent;

  guint counter;
  
  Atom selection_atom;
  Atom system_tray_opcode_atom;
  Window manager_wnd;

  GtkTooltips *tooltips;
};

struct _NotifyAreaIconClass
{
    GtkPlugClass parent_class;
};

typedef struct _NotifyAreaIcon NotifyAreaIcon;
typedef struct _NotifyAreaIconClass NotifyAreaIconClass;

extern  NotifyAreaIcon *notify_area_icon_new(const gchar *name);

guint        notify_area_icon_send_msg(NotifyAreaIcon *icon,
					   gint         timeout,
					   const char  *msg,
					   gint         length);

GType notify_area_icon_get_type (void);
					    
G_END_DECLS

#endif /* NOTIFY_AREA_ICON_H */


--- NEW FILE notify.def ---
;+NOTIFY_1.0 {       # NOTIFY release 1.0
;+    global:
LIBRARY notify  ;-
EXPORTS		;-
notify_icon_create;
notify_icon_create_with_image_file;
notify_icon_destroy;
notify_icon_created_ok;
;+    local:
;+       *;
;+};


--- NEW FILE notifytray.c ---
/** BEGIN COPYRIGHT BLOCK
 * This Program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; version 2 of the License.
 *
 * This Program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA.
 *
 * Copyright (C) 2005 Red Hat, Inc.
 * All rights reserved.
 * END COPYRIGHT BLOCK **/


#include <gtk/gtk.h>
#include <stdlib.h>
#include "notifyareaicon.h"
#include "notifytray.h"
#include "string.h"

#ifdef HAVE_LIB_NOTIFY
#include <libnotify/notify.h>
#endif

/* globals */
static NotifyAreaIcon *notify = NULL;

static GtkWidget *image = NULL;
static GdkPixbuf *blank_icon = NULL;
static GtkWidget *notify_menu = NULL;
static char *notify_image = NULL;

static GtkWidget *notify_box = NULL;


GtkWidget *notify_icon_get_box_widget()
{
    return notify_box;
}


void
notify_icon_embedded_cb(GtkWidget *widget, void *data)
{
	g_print ("notify_icon_embedded_cb\n");
}

void
notify_icon_destroyed_cb(GtkWidget *widget, void *data)
{
	g_print ("notify_icon_destroyed_cb\n");

	g_object_unref(G_OBJECT(notify));
	notify = NULL;
}

void
notify_icon_clicked_cb_local(GtkWidget *button, GdkEventButton *event, void *data)
{
	g_print ("notify_icon_clicked_cb_local.\n");

        if(notify_menu)
        {
            g_print("trying to create popup menu. \n");
            gtk_menu_popup(GTK_MENU(notify_menu),
                                             NULL,
                                             NULL,
                                             NULL,
                                             NULL,
                                             event->button,
                                             event->time);

        }
	if (event->type != GDK_BUTTON_PRESS)
		return;
}

void
notify_icon_destroy()
{
    g_print ("notify_icon_destroy\n");
    if(notify == NULL)
    {
        return;
    }

    g_signal_handlers_disconnect_by_func(G_OBJECT(notify),(void *) G_CALLBACK(notify_icon_destroyed_cb),NULL);

    gtk_widget_destroy(GTK_WIDGET(notify));

    g_object_unref(G_OBJECT(notify));
    notify = NULL;

    if (blank_icon)
         g_object_unref(G_OBJECT(blank_icon));

    blank_icon = NULL;
}

void notify_icon_create_with_image_file(char *image_file)
{
   if(notify_image)
   {
      free(notify_image);
      notify_image = NULL;
   }

   notify_image = strdup(image_file);

   notify_icon_create();
}

void
notify_icon_create()
{
	if (notify) {
            return;
	}

	notify = notify_area_icon_new("coolkey");

        if(!notify_box)
        {
	     notify_box = gtk_event_box_new();
        }

        if(notify_image)
        {
            g_print("about to create image from file %s \n",notify_image);
 
	    image = gtk_image_new_from_file(notify_image);

        }

	g_signal_connect(G_OBJECT(notify), "embedded", G_CALLBACK(notify_icon_embedded_cb), NULL);
	g_signal_connect(G_OBJECT(notify), "destroy", G_CALLBACK(notify_icon_destroyed_cb), NULL);
	gtk_container_add(GTK_CONTAINER(notify_box), image);
	gtk_container_add(GTK_CONTAINER(notify), notify_box);

	if(!gtk_check_version(2,4,0))
		g_object_set(G_OBJECT(notify_box), "visible-window", FALSE, NULL);


	gtk_widget_show_all(GTK_WIDGET(notify));

	/* reference the icon */
	g_object_ref(G_OBJECT(notify));

}

int notify_icon_created_ok()
{
  if(!notify)
      return 0;

  if(notify->manager_wnd)
    return 1;
  else
    return 0;

}

int notify_icon_show()
{

    if(!notify)
        return 0;

    gtk_widget_show(GTK_WIDGET(notify));

    return 1;

}

int notify_icon_hide()
{

   if(!notify)
       return 0;

   gtk_widget_hide(GTK_WIDGET(notify));

   return 1;
}

void notify_icon_set_static_tooltip(const gchar *message)
{
    if(!message || !notify)
        return;

    if(notify->tooltips)
    {
        gtk_tooltips_set_tip (notify->tooltips, GTK_WIDGET(notify), message, NULL);
    }
}

void notify_icon_send_tooltip_msg(const gchar *title,const gchar *message,gint severity,gint timeout,const char* icon)
{
    if(!message || !notify)
        return;

    gchar *msg_title = NULL;


    if(!title)
       msg_title = "Notification";
    else
       msg_title = title;
   
    gint msg_timeout = 3000; 
       
    if(timeout > 0  && timeout < 10000)
        msg_timeout = timeout;  

    #ifdef HAVE_LIB_NOTIFY

    if(!notify_is_initted()) 
    {
        notify_init ("ESC");
    }

    g_print("icon %s", icon);
    NotifyNotification *not = notify_notification_new(msg_title, message,icon, GTK_WIDGET(notify));

    if(not)
    {
        notify_notification_set_timeout (not, msg_timeout);

        if(!notify_notification_show (not, NULL))
        {
            g_print ("problem showing notification");
        }

        g_object_unref(G_OBJECT(not));
    }
    else
    {
         g_print ("problem creating notification object!\n");
    }

   #endif

}


--- NEW FILE notifytray.h ---
/** BEGIN COPYRIGHT BLOCK
 * This Program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; version 2 of the License.
 *
 * This Program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA.
 *
 * Copyright (C) 2005 Red Hat, Inc.
 * All rights reserved.
 * END COPYRIGHT BLOCK **/


#ifndef _NOTIFY_TRAY_H_
#define _NOTIFY_TRAY_H_

extern GtkWidget *notify_icon_get_box_widget();
extern void notify_icon_create();
extern void notify_icon_create_with_image_file(char *image_file_name);
extern void notify_icon_destroy();
extern int notify_icon_created_ok();
extern int notify_icon_show();
extern int notify_icon_hide();
extern void notify_icon_set_static_tooltip(const char *message);
extern void notify_icon_send_tooltip_msg(const char *title,const char *message,gint severity,gint timeout,const char *icon);
#endif /* _NOTIFY_TRAY_H_ */




More information about the Fedora-directory-commits mailing list