From 781b0ff3f74abd6f5353b6d08763bbba93f2f21c Mon Sep 17 00:00:00 2001 From: Perberos Date: Thu, 1 Dec 2011 22:49:12 -0300 Subject: moving from https://github.com/perberos/mate-desktop-environment --- src/daemon/Makefile.am | 30 + src/daemon/Makefile.in | 617 ++++++++++++++ src/daemon/daemon.c | 1650 +++++++++++++++++++++++++++++++++++++ src/daemon/daemon.h | 103 +++ src/daemon/engines.c | 338 ++++++++ src/daemon/engines.h | 60 ++ src/daemon/notificationdaemon.xml | 40 + src/daemon/sound.c | 39 + src/daemon/sound.h | 29 + src/daemon/stack.c | 409 +++++++++ src/daemon/stack.h | 50 ++ 11 files changed, 3365 insertions(+) create mode 100644 src/daemon/Makefile.am create mode 100644 src/daemon/Makefile.in create mode 100644 src/daemon/daemon.c create mode 100644 src/daemon/daemon.h create mode 100644 src/daemon/engines.c create mode 100644 src/daemon/engines.h create mode 100644 src/daemon/notificationdaemon.xml create mode 100644 src/daemon/sound.c create mode 100644 src/daemon/sound.h create mode 100644 src/daemon/stack.c create mode 100644 src/daemon/stack.h (limited to 'src/daemon') diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am new file mode 100644 index 0000000..4f9471c --- /dev/null +++ b/src/daemon/Makefile.am @@ -0,0 +1,30 @@ +libexec_PROGRAMS = mate-notification-daemon + +mate_notification_daemon_SOURCES = \ + daemon.c \ + daemon.h \ + engines.c \ + engines.h \ + stack.c \ + stack.h \ + sound.c \ + sound.h + +mate_notification_daemon_LDADD = $(NOTIFICATION_DAEMON_LIBS) + +BUILT_SOURCES = notificationdaemon-dbus-glue.h + +notificationdaemon-dbus-glue.h: notificationdaemon.xml + dbus-binding-tool --mode=glib-server --prefix=notification_daemon \ + $(srcdir)/notificationdaemon.xml > notificationdaemon-dbus-glue.h + +INCLUDES = \ + -I$(top_srcdir) \ + $(NOTIFICATION_DAEMON_CFLAGS) \ + -DENGINES_DIR=\"$(libdir)/mate-notification-daemon/engines\" + +EXTRA_DIST = notificationdaemon.xml +DISTCLEANFILES = \ + notificationdaemon-dbus-glue.h + +-include $(top_srcdir)/git.mk diff --git a/src/daemon/Makefile.in b/src/daemon/Makefile.in new file mode 100644 index 0000000..8978c97 --- /dev/null +++ b/src/daemon/Makefile.in @@ -0,0 +1,617 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +libexec_PROGRAMS = mate-notification-daemon$(EXEEXT) +subdir = src/daemon +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/macros/intltool.m4 \ + $(top_srcdir)/macros/libtool.m4 \ + $(top_srcdir)/macros/ltoptions.m4 \ + $(top_srcdir)/macros/ltsugar.m4 \ + $(top_srcdir)/macros/ltversion.m4 \ + $(top_srcdir)/macros/lt~obsolete.m4 $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__installdirs = "$(DESTDIR)$(libexecdir)" +PROGRAMS = $(libexec_PROGRAMS) +am_mate_notification_daemon_OBJECTS = daemon.$(OBJEXT) \ + engines.$(OBJEXT) stack.$(OBJEXT) sound.$(OBJEXT) +mate_notification_daemon_OBJECTS = \ + $(am_mate_notification_daemon_OBJECTS) +am__DEPENDENCIES_1 = +mate_notification_daemon_DEPENDENCIES = $(am__DEPENDENCIES_1) +AM_V_lt = $(am__v_lt_$(V)) +am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) +am__v_lt_0 = --silent +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_$(V)) +am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) +am__v_CC_0 = @echo " CC " $@; +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_$(V)) +am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) +am__v_CCLD_0 = @echo " CCLD " $@; +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; +SOURCES = $(mate_notification_daemon_SOURCES) +DIST_SOURCES = $(mate_notification_daemon_SOURCES) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +ALL_LINGUAS = @ALL_LINGUAS@ +AMTAR = @AMTAR@ +AM_CFLAGS = @AM_CFLAGS@ +AM_CXXFLAGS = @AM_CXXFLAGS@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CATALOGS = @CATALOGS@ +CATOBJEXT = @CATOBJEXT@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATADIR = @DATADIR@ +DATADIRNAME = @DATADIRNAME@ +DBUS_SERVICES_DIR = @DBUS_SERVICES_DIR@ +DBUS_SYS_DIR = @DBUS_SYS_DIR@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DISABLE_DEPRECATED = @DISABLE_DEPRECATED@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GETTEXT_PACKAGE = @GETTEXT_PACKAGE@ +GMOFILES = @GMOFILES@ +GMSGFMT = @GMSGFMT@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +INSTOBJEXT = @INSTOBJEXT@ +INTLLIBS = @INTLLIBS@ +INTLTOOL_EXTRACT = @INTLTOOL_EXTRACT@ +INTLTOOL_MERGE = @INTLTOOL_MERGE@ +INTLTOOL_PERL = @INTLTOOL_PERL@ +INTLTOOL_UPDATE = @INTLTOOL_UPDATE@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDIR = @LIBDIR@ +LIBEXECDIR = @LIBEXECDIR@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MATECONFTOOL = @MATECONFTOOL@ +MATECONF_SCHEMA_CONFIG_SOURCE = @MATECONF_SCHEMA_CONFIG_SOURCE@ +MATECONF_SCHEMA_FILE_DIR = @MATECONF_SCHEMA_FILE_DIR@ +MKDIR_P = @MKDIR_P@ +MKINSTALLDIRS = @MKINSTALLDIRS@ +MSGFMT = @MSGFMT@ +MSGFMT_OPTS = @MSGFMT_OPTS@ +MSGMERGE = @MSGMERGE@ +NM = @NM@ +NMEDIT = @NMEDIT@ +NOTIFICATION_CAPPLET_CFLAGS = @NOTIFICATION_CAPPLET_CFLAGS@ +NOTIFICATION_CAPPLET_LIBS = @NOTIFICATION_CAPPLET_LIBS@ +NOTIFICATION_DAEMON_CFLAGS = @NOTIFICATION_DAEMON_CFLAGS@ +NOTIFICATION_DAEMON_LIBS = @NOTIFICATION_DAEMON_LIBS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +POFILES = @POFILES@ +POSUB = @POSUB@ +PO_IN_DATADIR_FALSE = @PO_IN_DATADIR_FALSE@ +PO_IN_DATADIR_TRUE = @PO_IN_DATADIR_TRUE@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +SYSCONFDIR = @SYSCONFDIR@ +THEME_CFLAGS = @THEME_CFLAGS@ +THEME_LIBS = @THEME_LIBS@ +USE_NLS = @USE_NLS@ +VERSION = @VERSION@ +WARN_CFLAGS = @WARN_CFLAGS@ +WARN_CXXFLAGS = @WARN_CXXFLAGS@ +XGETTEXT = @XGETTEXT@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +mate_notification_daemon_SOURCES = \ + daemon.c \ + daemon.h \ + engines.c \ + engines.h \ + stack.c \ + stack.h \ + sound.c \ + sound.h + +mate_notification_daemon_LDADD = $(NOTIFICATION_DAEMON_LIBS) +BUILT_SOURCES = notificationdaemon-dbus-glue.h +INCLUDES = \ + -I$(top_srcdir) \ + $(NOTIFICATION_DAEMON_CFLAGS) \ + -DENGINES_DIR=\"$(libdir)/mate-notification-daemon/engines\" + +EXTRA_DIST = notificationdaemon.xml +DISTCLEANFILES = \ + notificationdaemon-dbus-glue.h + +all: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/daemon/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/daemon/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-libexecPROGRAMS: $(libexec_PROGRAMS) + @$(NORMAL_INSTALL) + test -z "$(libexecdir)" || $(MKDIR_P) "$(DESTDIR)$(libexecdir)" + @list='$(libexec_PROGRAMS)'; test -n "$(libexecdir)" || list=; \ + for p in $$list; do echo "$$p $$p"; done | \ + sed 's/$(EXEEXT)$$//' | \ + while read p p1; do if test -f $$p || test -f $$p1; \ + then echo "$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \ + -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ + sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) files[d] = files[d] " " $$1; \ + else { print "f", $$3 "/" $$4, $$1; } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(libexecdir)$$dir'"; \ + $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(libexecdir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-libexecPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(libexec_PROGRAMS)'; test -n "$(libexecdir)" || list=; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ + -e 's/$$/$(EXEEXT)/' `; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(libexecdir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(libexecdir)" && rm -f $$files + +clean-libexecPROGRAMS: + @list='$(libexec_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list +mate-notification-daemon$(EXEEXT): $(mate_notification_daemon_OBJECTS) $(mate_notification_daemon_DEPENDENCIES) + @rm -f mate-notification-daemon$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(mate_notification_daemon_OBJECTS) $(mate_notification_daemon_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/daemon.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/engines.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sound.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stack.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) check-am +all-am: Makefile $(PROGRAMS) +installdirs: + for dir in "$(DESTDIR)$(libexecdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + -test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." + -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) +clean: clean-am + +clean-am: clean-generic clean-libexecPROGRAMS clean-libtool \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-libexecPROGRAMS + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-libexecPROGRAMS + +.MAKE: all check install install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libexecPROGRAMS clean-libtool ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am \ + install-libexecPROGRAMS install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-libexecPROGRAMS + + +notificationdaemon-dbus-glue.h: notificationdaemon.xml + dbus-binding-tool --mode=glib-server --prefix=notification_daemon \ + $(srcdir)/notificationdaemon.xml > notificationdaemon-dbus-glue.h + +-include $(top_srcdir)/git.mk + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c new file mode 100644 index 0000000..8241c6d --- /dev/null +++ b/src/daemon/daemon.c @@ -0,0 +1,1650 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * Copyright (C) 2006 Christian Hammond + * Copyright (C) 2005 John (J5) Palmieri + * Copyright (C) 2010 Red Hat, Inc. + * Copyright (C) 2011 Perberos + * + * 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; either version 2, or (at your option) + * any later version. + * + * 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. + */ + +#include "config.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#define WNCK_I_KNOW_THIS_IS_UNSTABLE +#include + +#include "daemon.h" +#include "engines.h" +#include "stack.h" +#include "sound.h" +#include "notificationdaemon-dbus-glue.h" + +#define MAX_NOTIFICATIONS 20 + +#define IMAGE_SIZE 48 +#define IDLE_SECONDS 30 +#define NOTIFICATION_BUS_NAME "org.freedesktop.Notifications" +#define NOTIFICATION_BUS_PATH "/org/freedesktop/Notifications" + +#define NW_GET_NOTIFY_ID(nw) \ + (GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(nw), "_notify_id"))) +#define NW_GET_NOTIFY_SENDER(nw) \ + (g_object_get_data(G_OBJECT(nw), "_notify_sender")) +#define NW_GET_DAEMON(nw) \ + (g_object_get_data(G_OBJECT(nw), "_notify_daemon")) + +typedef struct { + NotifyStackLocation type; + const char* identifier; +} PopupNotifyStackLocation; + +const PopupNotifyStackLocation popup_stack_locations[] = { + {NOTIFY_STACK_LOCATION_TOP_LEFT, "top_left"}, + {NOTIFY_STACK_LOCATION_TOP_RIGHT, "top_right"}, + {NOTIFY_STACK_LOCATION_BOTTOM_LEFT, "bottom_left"}, + {NOTIFY_STACK_LOCATION_BOTTOM_RIGHT, "bottom_right"}, + {NOTIFY_STACK_LOCATION_UNKNOWN, NULL} +}; + +#define POPUP_STACK_DEFAULT_INDEX 3 /* XXX Hack! */ + +typedef struct { + NotifyDaemon* daemon; + GTimeVal expiration; + GTimeVal paused_diff; + guint id; + GtkWindow* nw; + Window src_window_xid; + guint has_timeout: 1; + guint paused: 1; +} NotifyTimeout; + +typedef struct { + NotifyStack** stacks; + int n_stacks; + Atom workarea_atom; +} NotifyScreen; + +struct _NotifyDaemonPrivate { + guint next_id; + guint timeout_source; + guint exit_timeout_source; + GHashTable* idle_reposition_notify_ids; + GHashTable* monitored_window_hash; + GHashTable* notification_hash; + gboolean url_clicked_lock; + + guint mateconf_cnxn; + + NotifyStackLocation stack_location; + NotifyScreen** screens; + int n_screens; +}; + +typedef struct { + guint id; + NotifyDaemon* daemon; +} _NotifyPendingClose; + +static DBusConnection* dbus_conn = NULL; + +static void notify_daemon_finalize(GObject* object); +static void _notification_destroyed_cb(GtkWindow* nw, NotifyDaemon* daemon); +static void _close_notification(NotifyDaemon* daemon, guint id, gboolean hide_notification, NotifydClosedReason reason); +static GdkFilterReturn _notify_x11_filter(GdkXEvent* xevent, GdkEvent* event, NotifyDaemon* daemon); +static void _emit_closed_signal(GtkWindow* nw, NotifydClosedReason reason); +static void _action_invoked_cb(GtkWindow* nw, const char* key); +static NotifyStackLocation get_stack_location_from_string(const char* slocation); +static void sync_notification_position(NotifyDaemon* daemon, GtkWindow* nw, Window source); +static void monitor_notification_source_windows(NotifyDaemon* daemon, NotifyTimeout* nt, Window source); + +G_DEFINE_TYPE(NotifyDaemon, notify_daemon, G_TYPE_OBJECT); + +static void notify_daemon_class_init(NotifyDaemonClass* daemon_class) +{ + GObjectClass* object_class = G_OBJECT_CLASS(daemon_class); + + object_class->finalize = notify_daemon_finalize; + + g_type_class_add_private(daemon_class, sizeof(NotifyDaemonPrivate)); +} + +static void _notify_timeout_destroy(NotifyTimeout* nt) +{ + /* + * Disconnect the destroy handler to avoid a loop since the id + * won't be removed from the hash table before the widget is + * destroyed. + */ + g_signal_handlers_disconnect_by_func(nt->nw, _notification_destroyed_cb, nt->daemon); + gtk_widget_destroy(GTK_WIDGET(nt->nw)); + g_free(nt); +} + +static gboolean do_exit(gpointer user_data) +{ + //g_debug("Exiting due to inactivity"); + exit(1); + + return FALSE; +} + +static void add_exit_timeout(NotifyDaemon* daemon) +{ + if (daemon->priv->exit_timeout_source > 0) + { + return; + } + + daemon->priv->exit_timeout_source = g_timeout_add_seconds(IDLE_SECONDS, do_exit, NULL); +} + +static void remove_exit_timeout(NotifyDaemon* daemon) +{ + if (daemon->priv->exit_timeout_source == 0) + { + return; + } + + g_source_remove(daemon->priv->exit_timeout_source); + daemon->priv->exit_timeout_source = 0; +} + +static void create_stack_for_monitor(NotifyDaemon* daemon, GdkScreen* screen, int monitor_num) +{ + int screen_num = gdk_screen_get_number(screen); + NotifyScreen* nscreen = daemon->priv->screens[screen_num]; + + nscreen->stacks[monitor_num] = notify_stack_new(daemon, screen, monitor_num, daemon->priv->stack_location); +} + +static void on_screen_monitors_changed(GdkScreen* screen, NotifyDaemon* daemon) +{ + NotifyScreen* nscreen; + int screen_num; + int n_monitors; + int i; + + screen_num = gdk_screen_get_number(screen); + nscreen = daemon->priv->screens[screen_num]; + + n_monitors = gdk_screen_get_n_monitors(screen); + + if (n_monitors > nscreen->n_stacks) + { + /* grow */ + nscreen->stacks = g_renew(NotifyStack *, nscreen->stacks, n_monitors); + + /* add more stacks */ + for (i = nscreen->n_stacks; i < n_monitors; i++) + { + create_stack_for_monitor(daemon, screen, i); + } + + nscreen->n_stacks = n_monitors; + } + else if (n_monitors < nscreen->n_stacks) + { + NotifyStack* last_stack; + + last_stack = nscreen->stacks[n_monitors - 1]; + + /* transfer items before removing stacks */ + for (i = n_monitors; i < nscreen->n_stacks; i++) + { + NotifyStack* stack = nscreen->stacks[i]; + GList* windows = g_list_copy(notify_stack_get_windows(stack)); + GList* l; + + for (l = windows; l != NULL; l = l->next) + { + /* skip removing the window from the old stack since it will try + * to unrealize the window. + * And the stack is going away anyhow. */ + notify_stack_add_window(last_stack, l->data, TRUE); + } + + g_list_free(windows); + notify_stack_destroy(stack); + nscreen->stacks[i] = NULL; + } + + /* remove the extra stacks */ + nscreen->stacks = g_renew(NotifyStack*, nscreen->stacks, n_monitors); + nscreen->n_stacks = n_monitors; + } +} + +static void create_stacks_for_screen(NotifyDaemon* daemon, GdkScreen *screen) +{ + NotifyScreen* nscreen; + int screen_num; + int i; + + screen_num = gdk_screen_get_number(screen); + nscreen = daemon->priv->screens[screen_num]; + + nscreen->n_stacks = gdk_screen_get_n_monitors(screen); + + nscreen->stacks = g_renew(NotifyStack*, nscreen->stacks, nscreen->n_stacks); + + for (i = 0; i < nscreen->n_stacks; i++) + { + create_stack_for_monitor(daemon, screen, i); + } +} + +static GdkFilterReturn screen_xevent_filter(GdkXEvent* xevent, GdkEvent* event, NotifyScreen* nscreen) +{ + XEvent* xev = (XEvent*) xevent; + + if (xev->type == PropertyNotify && xev->xproperty.atom == nscreen->workarea_atom) + { + int i; + + for (i = 0; i < nscreen->n_stacks; i++) + { + notify_stack_queue_update_position(nscreen->stacks[i]); + } + } + + return GDK_FILTER_CONTINUE; +} + +static void create_screens(NotifyDaemon* daemon) +{ + GdkDisplay* display; + int i; + + g_assert(daemon->priv->screens == NULL); + + display = gdk_display_get_default(); + daemon->priv->n_screens = gdk_display_get_n_screens(display); + + daemon->priv->screens = g_new0(NotifyScreen *, daemon->priv->n_screens); + + for (i = 0; i < daemon->priv->n_screens; i++) + { + GdkScreen* screen; + GdkWindow* gdkwindow; + + screen = gdk_display_get_screen(display, i); + g_signal_connect(screen, "monitors-changed", G_CALLBACK(on_screen_monitors_changed), daemon); + + daemon->priv->screens[i] = g_new0(NotifyScreen, 1); + + #if GTK_CHECK_VERSION(3, 0, 0) + daemon->priv->screens[i]->workarea_atom = XInternAtom(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "_NET_WORKAREA", True); + #else + daemon->priv->screens[i]->workarea_atom = XInternAtom(GDK_DISPLAY(), "_NET_WORKAREA", True); + #endif + + gdkwindow = gdk_screen_get_root_window(screen); + gdk_window_add_filter(gdkwindow, (GdkFilterFunc) screen_xevent_filter, daemon->priv->screens[i]); + gdk_window_set_events(gdkwindow, gdk_window_get_events(gdkwindow) | GDK_PROPERTY_CHANGE_MASK); + + create_stacks_for_screen(daemon, gdk_display_get_screen(display, i)); + } +} + +static void on_popup_location_changed(MateConfClient* client, guint cnxn_id, MateConfEntry* entry, NotifyDaemon* daemon) +{ + NotifyStackLocation stack_location; + const char* slocation; + MateConfValue* value; + int i; + + value = mateconf_entry_get_value(entry); + slocation = (value != NULL ? mateconf_value_get_string(value) : NULL); + + if (slocation != NULL && *slocation != '\0') + { + stack_location = get_stack_location_from_string(slocation); + } + else + { + mateconf_client_set_string(client, MATECONF_KEY_POPUP_LOCATION, popup_stack_locations[POPUP_STACK_DEFAULT_INDEX].identifier, NULL); + + stack_location = NOTIFY_STACK_LOCATION_DEFAULT; + } + + daemon->priv->stack_location = stack_location; + + for (i = 0; i < daemon->priv->n_screens; i++) + { + int j; + + for (j = 0; j < daemon->priv->n_screens; j++) + { + NotifyStack* stack; + stack = daemon->priv->screens[i]->stacks[j]; + notify_stack_set_location(stack, stack_location); + } + } +} + +static void notify_daemon_init(NotifyDaemon* daemon) +{ + MateConfClient* client; + char* location; + + daemon->priv = G_TYPE_INSTANCE_GET_PRIVATE(daemon, NOTIFY_TYPE_DAEMON, NotifyDaemonPrivate); + + daemon->priv->next_id = 1; + daemon->priv->timeout_source = 0; + + add_exit_timeout(daemon); + + client = mateconf_client_get_default(); + mateconf_client_add_dir(client, MATECONF_KEY_DAEMON, MATECONF_CLIENT_PRELOAD_NONE, NULL); + + location = mateconf_client_get_string(client, MATECONF_KEY_POPUP_LOCATION, NULL); + daemon->priv->stack_location = get_stack_location_from_string(location); + g_free(location); + + daemon->priv->mateconf_cnxn = mateconf_client_notify_add(client, MATECONF_KEY_POPUP_LOCATION, (MateConfClientNotifyFunc) on_popup_location_changed, daemon, NULL, NULL); + g_object_unref(client); + + daemon->priv->n_screens = 0; + daemon->priv->screens = NULL; + + create_screens(daemon); + + daemon->priv->idle_reposition_notify_ids = g_hash_table_new(NULL, NULL); + daemon->priv->monitored_window_hash = g_hash_table_new(NULL, NULL); + daemon->priv->notification_hash = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, (GDestroyNotify) _notify_timeout_destroy); +} + +static void destroy_screens(NotifyDaemon* daemon) +{ + GdkDisplay* display; + int i; + int j; + + display = gdk_display_get_default(); + + for (i = 0; i < daemon->priv->n_screens; i++) + { + GdkScreen* screen; + GdkWindow* gdkwindow; + + screen = gdk_display_get_screen(display, i); + g_signal_handlers_disconnect_by_func(screen, G_CALLBACK(on_screen_monitors_changed), daemon); + + gdkwindow = gdk_screen_get_root_window(screen); + gdk_window_remove_filter(gdkwindow, (GdkFilterFunc) screen_xevent_filter, daemon->priv->screens[i]); + + for (j = 0; i < daemon->priv->screens[i]->n_stacks; j++) + { + notify_stack_destroy(daemon->priv->screens[i]->stacks[j]); + daemon->priv->screens[i]->stacks[j] = NULL; + } + + g_free(daemon->priv->screens[i]->stacks); + } + + g_free(daemon->priv->screens); + daemon->priv->screens = NULL; +} + +static void notify_daemon_finalize(GObject* object) +{ + NotifyDaemon* daemon; + MateConfClient* client; + + daemon = NOTIFY_DAEMON(object); + + client = mateconf_client_get_default(); + mateconf_client_notify_remove(client, daemon->priv->mateconf_cnxn); + g_object_unref(client); + + if (g_hash_table_size(daemon->priv->monitored_window_hash) > 0) + { + gdk_window_remove_filter(NULL, (GdkFilterFunc) _notify_x11_filter, daemon); + } + + remove_exit_timeout(daemon); + + g_hash_table_destroy(daemon->priv->monitored_window_hash); + g_hash_table_destroy(daemon->priv->idle_reposition_notify_ids); + g_hash_table_destroy(daemon->priv->notification_hash); + + destroy_screens(daemon); + + g_free(daemon->priv); + + G_OBJECT_CLASS(notify_daemon_parent_class)->finalize(object); +} + +static NotifyStackLocation get_stack_location_from_string(const char* slocation) +{ + NotifyStackLocation stack_location = NOTIFY_STACK_LOCATION_DEFAULT; + + if (slocation == NULL || *slocation == '\0') + { + return NOTIFY_STACK_LOCATION_DEFAULT; + } + else + { + const PopupNotifyStackLocation* l; + + for (l = popup_stack_locations; l->type != NOTIFY_STACK_LOCATION_UNKNOWN; l++) + { + if (!strcmp(slocation, l->identifier)) + { + stack_location = l->type; + } + } + } + + return stack_location; +} + +static DBusMessage* create_signal(GtkWindow* nw, const char* signal_name) +{ + guint id; + char* dest; + DBusMessage* message; + + id = NW_GET_NOTIFY_ID(nw); + dest = NW_GET_NOTIFY_SENDER(nw); + + g_assert(dest != NULL); + + message = dbus_message_new_signal(NOTIFICATION_BUS_PATH, NOTIFICATION_BUS_NAME, signal_name); + + dbus_message_set_destination(message, dest); + dbus_message_append_args(message, DBUS_TYPE_UINT32, &id, DBUS_TYPE_INVALID); + + return message; +} + +static void _action_invoked_cb(GtkWindow* nw, const char *key) +{ + NotifyDaemon* daemon; + guint id; + DBusMessage* message; + + daemon = NW_GET_DAEMON(nw); + id = NW_GET_NOTIFY_ID(nw); + + message = create_signal(nw, "ActionInvoked"); + dbus_message_append_args(message, DBUS_TYPE_STRING, &key, DBUS_TYPE_INVALID); + + dbus_connection_send(dbus_conn, message, NULL); + dbus_message_unref(message); + + _close_notification(daemon, id, TRUE, NOTIFYD_CLOSED_USER); +} + +static void _emit_closed_signal(GtkWindow* nw, NotifydClosedReason reason) +{ + DBusMessage* message = create_signal(nw, "NotificationClosed"); + dbus_message_append_args(message, DBUS_TYPE_UINT32, &reason, DBUS_TYPE_INVALID); + dbus_connection_send(dbus_conn, message, NULL); + dbus_message_unref(message); +} + +static void _close_notification(NotifyDaemon* daemon, guint id, gboolean hide_notification, NotifydClosedReason reason) +{ + NotifyDaemonPrivate* priv = daemon->priv; + NotifyTimeout* nt; + + nt = (NotifyTimeout*) g_hash_table_lookup(priv->notification_hash, &id); + + if (nt != NULL) + { + _emit_closed_signal(nt->nw, reason); + + if (hide_notification) + { + theme_hide_notification(nt->nw); + } + + g_hash_table_remove(priv->notification_hash, &id); + + if (g_hash_table_size(daemon->priv->notification_hash) == 0) + { + add_exit_timeout(daemon); + } + } +} + +static gboolean _close_notification_not_shown(_NotifyPendingClose* data) +{ + _close_notification(data->daemon, data->id, TRUE, NOTIFYD_CLOSED_RESERVED); + g_object_unref(data->daemon); + g_free(data); + + return FALSE; +} + +static void _notification_destroyed_cb(GtkWindow* nw, NotifyDaemon* daemon) +{ + /* + * This usually won't happen, but can if notification-daemon dies before + * all notifications are closed. Mark them as expired. + */ + _close_notification(daemon, NW_GET_NOTIFY_ID(nw), FALSE, NOTIFYD_CLOSED_EXPIRED); +} + +typedef struct { + NotifyDaemon* daemon; + gint id; +} IdleRepositionData; + +static gboolean idle_reposition_notification(IdleRepositionData* data) +{ + NotifyDaemon* daemon; + NotifyTimeout* nt; + gint notify_id; + + daemon = data->daemon; + notify_id = data->id; + + /* Look up the timeout, if it's completed we don't need to do anything */ + nt = (NotifyTimeout*) g_hash_table_lookup(daemon->priv->notification_hash, ¬ify_id); + + if (nt != NULL) + { + sync_notification_position(daemon, nt->nw, nt->src_window_xid); + } + + g_hash_table_remove(daemon->priv->idle_reposition_notify_ids, GINT_TO_POINTER(notify_id)); + g_object_unref(daemon); + g_free(data); + + return FALSE; +} + +static void _queue_idle_reposition_notification(NotifyDaemon* daemon, gint notify_id) +{ + IdleRepositionData* data; + gpointer orig_key; + gpointer value; + guint idle_id; + + /* Do we already have an idle update pending? */ + if (g_hash_table_lookup_extended(daemon->priv->idle_reposition_notify_ids, GINT_TO_POINTER(notify_id), &orig_key, &value)) + { + return; + } + + data = g_new0(IdleRepositionData, 1); + data->daemon = g_object_ref(daemon); + data->id = notify_id; + + /* We do this as a short timeout to avoid repositioning spam */ + idle_id = g_timeout_add_full(G_PRIORITY_LOW, 50, (GSourceFunc) idle_reposition_notification, data, NULL); + g_hash_table_insert(daemon->priv->idle_reposition_notify_ids, GINT_TO_POINTER(notify_id), GUINT_TO_POINTER(idle_id)); +} + +static GdkFilterReturn _notify_x11_filter(GdkXEvent* xevent, GdkEvent* event, NotifyDaemon* daemon) +{ + XEvent* xev; + gpointer orig_key; + gpointer value; + gint notify_id; + NotifyTimeout* nt; + + xev = (XEvent*) xevent; + + if (xev->xany.type == DestroyNotify) + { + g_hash_table_remove(daemon->priv->monitored_window_hash, GUINT_TO_POINTER(xev->xany.window)); + + if (g_hash_table_size(daemon->priv->monitored_window_hash) == 0) + { + gdk_window_remove_filter(NULL, (GdkFilterFunc) _notify_x11_filter, daemon); + } + + return GDK_FILTER_CONTINUE; + } + + if (!g_hash_table_lookup_extended(daemon->priv->monitored_window_hash, GUINT_TO_POINTER(xev->xany.window), &orig_key, &value)) + { + return GDK_FILTER_CONTINUE; + } + + notify_id = GPOINTER_TO_INT(value); + + if (xev->xany.type == ConfigureNotify || xev->xany.type == MapNotify) + { + _queue_idle_reposition_notification(daemon, notify_id); + } + else if (xev->xany.type == ReparentNotify) + { + nt = (NotifyTimeout *) g_hash_table_lookup(daemon->priv->notification_hash, ¬ify_id); + + if (nt == NULL) + { + return GDK_FILTER_CONTINUE; + } + + /* + * If the window got reparented, we need to start monitoring the + * new parents. + */ + monitor_notification_source_windows(daemon, nt, nt->src_window_xid); + sync_notification_position(daemon, nt->nw, nt->src_window_xid); + } + + return GDK_FILTER_CONTINUE; +} + +static void _mouse_entered_cb(GtkWindow* nw, GdkEventCrossing* event, NotifyDaemon* daemon) +{ + NotifyTimeout* nt; + guint id; + GTimeVal now; + + if (event->detail == GDK_NOTIFY_INFERIOR) + { + return; + } + + id = NW_GET_NOTIFY_ID(nw); + nt = (NotifyTimeout*) g_hash_table_lookup(daemon->priv->notification_hash, &id); + + nt->paused = TRUE; + g_get_current_time(&now); + + nt->paused_diff.tv_usec = nt->expiration.tv_usec - now.tv_usec; + nt->paused_diff.tv_sec = nt->expiration.tv_sec - now.tv_sec; + + if (nt->paused_diff.tv_usec < 0) + { + nt->paused_diff.tv_usec += G_USEC_PER_SEC; + nt->paused_diff.tv_sec--; + } +} + +static void _mouse_exitted_cb(GtkWindow* nw, GdkEventCrossing* event, NotifyDaemon* daemon) +{ + if (event->detail == GDK_NOTIFY_INFERIOR) + { + return; + } + + guint id = NW_GET_NOTIFY_ID(nw); + NotifyTimeout* nt = (NotifyTimeout*) g_hash_table_lookup(daemon->priv->notification_hash, &id); + + nt->paused = FALSE; +} + +static gboolean _is_expired(gpointer key, NotifyTimeout* nt, gboolean* phas_more_timeouts) +{ + time_t now_time; + time_t expiration_time; + GTimeVal now; + + if (!nt->has_timeout) + { + return FALSE; + } + + g_get_current_time(&now); + + expiration_time = (nt->expiration.tv_sec * 1000) + (nt->expiration.tv_usec / 1000); + now_time = (now.tv_sec * 1000) + (now.tv_usec / 1000); + + if (now_time > expiration_time) + { + theme_notification_tick(nt->nw, 0); + _emit_closed_signal(nt->nw, NOTIFYD_CLOSED_EXPIRED); + return TRUE; + } + else if (nt->paused) + { + nt->expiration.tv_usec = nt->paused_diff.tv_usec + now.tv_usec; + nt->expiration.tv_sec = nt->paused_diff.tv_sec + now.tv_sec; + + if (nt->expiration.tv_usec >= G_USEC_PER_SEC) + { + nt->expiration.tv_usec -= G_USEC_PER_SEC; + nt->expiration.tv_sec++; + } + } + else + { + theme_notification_tick(nt->nw, expiration_time - now_time); + } + + *phas_more_timeouts = TRUE; + + return FALSE; +} + +static gboolean _check_expiration(NotifyDaemon* daemon) +{ + gboolean has_more_timeouts = FALSE; + + g_hash_table_foreach_remove(daemon->priv->notification_hash, (GHRFunc) _is_expired, (gpointer) &has_more_timeouts); + + if (!has_more_timeouts) + { + daemon->priv->timeout_source = 0; + + if (g_hash_table_size (daemon->priv->notification_hash) == 0) + { + add_exit_timeout(daemon); + } + } + + return has_more_timeouts; +} + +static void _calculate_timeout(NotifyDaemon* daemon, NotifyTimeout* nt, int timeout) +{ + if (timeout == 0) + { + nt->has_timeout = FALSE; + } + else + { + nt->has_timeout = TRUE; + + if (timeout == -1) + { + timeout = NOTIFY_DAEMON_DEFAULT_TIMEOUT; + } + + theme_set_notification_timeout(nt->nw, timeout); + + glong usec = timeout * 1000; /* convert from msec to usec */ + + /* + * If it's less than 0, wrap around back to MAXLONG. + * g_time_val_add() requires a glong, and anything larger than + * MAXLONG will be treated as a negative value. + */ + if (usec < 0) + { + usec = G_MAXLONG; + } + + g_get_current_time(&nt->expiration); + g_time_val_add(&nt->expiration, usec); + + if (daemon->priv->timeout_source == 0) + { + daemon->priv->timeout_source = g_timeout_add(100, (GSourceFunc) _check_expiration, daemon); + } + } +} + +static NotifyTimeout* _store_notification(NotifyDaemon* daemon, GtkWindow* nw, int timeout) +{ + NotifyDaemonPrivate* priv = daemon->priv; + NotifyTimeout* nt; + guint id = 0; + + do { + id = priv->next_id; + + if (id != UINT_MAX) + { + priv->next_id++; + } + else + { + priv->next_id = 1; + } + + if (g_hash_table_lookup (priv->notification_hash, &id) != NULL) + { + id = 0; + } + + } while (id == 0); + + nt = g_new0(NotifyTimeout, 1); + nt->id = id; + nt->nw = nw; + nt->daemon = daemon; + + _calculate_timeout(daemon, nt, timeout); + + g_hash_table_insert(priv->notification_hash, g_memdup(&id, sizeof(guint)), nt); + remove_exit_timeout(daemon); + + return nt; +} + +static GdkPixbuf* _notify_daemon_pixbuf_from_data_hint(GValue* icon_data) +{ + const guchar* data = NULL; + gboolean has_alpha; + int bits_per_sample; + int width; + int height; + int rowstride; + int n_channels; + gsize expected_len; + GdkPixbuf* pixbuf; + GValueArray* image_struct; + GValue* value; + GArray* tmp_array; + GType struct_type; + + struct_type = dbus_g_type_get_struct("GValueArray", G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_BOOLEAN, G_TYPE_INT, G_TYPE_INT, dbus_g_type_get_collection ("GArray", G_TYPE_UCHAR), G_TYPE_INVALID); + + if (!G_VALUE_HOLDS (icon_data, struct_type)) + { + g_warning ("_notify_daemon_pixbuf_from_data_hint expected a GValue of type GValueArray"); + return NULL; + } + + image_struct = (GValueArray *) g_value_get_boxed (icon_data); + value = g_value_array_get_nth (image_struct, 0); + + if (value == NULL) + { + g_warning ("_notify_daemon_pixbuf_from_data_hint expected position 0 of the GValueArray to exist"); + return NULL; + } + + if (!G_VALUE_HOLDS (value, G_TYPE_INT)) + { + g_warning ("_notify_daemon_pixbuf_from_data_hint expected position 0 of the GValueArray to be of type int"); + return NULL; + } + + width = g_value_get_int (value); + value = g_value_array_get_nth (image_struct, 1); + + if (value == NULL) + { + g_warning ("_notify_daemon_pixbuf_from_data_hint expected position 1 of the GValueArray to exist"); + return NULL; + } + + if (!G_VALUE_HOLDS (value, G_TYPE_INT)) + { + g_warning ("_notify_daemon_pixbuf_from_data_hint expected position 1 of the GValueArray to be of type int"); + return NULL; + } + + height = g_value_get_int (value); + value = g_value_array_get_nth (image_struct, 2); + + if (value == NULL) + { + g_warning ("_notify_daemon_pixbuf_from_data_hint expected position 2 of the GValueArray to exist"); + return NULL; + } + + if (!G_VALUE_HOLDS (value, G_TYPE_INT)) + { + g_warning ("_notify_daemon_pixbuf_from_data_hint expected position 2 of the GValueArray to be of type int"); + return NULL; + } + + rowstride = g_value_get_int (value); + value = g_value_array_get_nth (image_struct, 3); + + if (value == NULL) + { + g_warning ("_notify_daemon_pixbuf_from_data_hint expected position 3 of the GValueArray to exist"); + return NULL; + } + + if (!G_VALUE_HOLDS (value, G_TYPE_BOOLEAN)) + { + g_warning ("_notify_daemon_pixbuf_from_data_hint expected position 3 of the GValueArray to be of type gboolean"); + return NULL; + } + + has_alpha = g_value_get_boolean (value); + value = g_value_array_get_nth (image_struct, 4); + + if (value == NULL) { + g_warning ("_notify_daemon_pixbuf_from_data_hint expected position 4 of the GValueArray to exist"); + return NULL; + } + + if (!G_VALUE_HOLDS (value, G_TYPE_INT)) + { + g_warning ("_notify_daemon_pixbuf_from_data_hint expected position 4 of the GValueArray to be of type int"); + return NULL; + } + + bits_per_sample = g_value_get_int (value); + value = g_value_array_get_nth (image_struct, 5); + + if (value == NULL) + { + g_warning ("_notify_daemon_pixbuf_from_data_hint expected position 5 of the GValueArray to exist"); + return NULL; + } + + if (!G_VALUE_HOLDS (value, G_TYPE_INT)) + { + g_warning ("_notify_daemon_pixbuf_from_data_hint expected position 5 of the GValueArray to be of type int"); + return NULL; + } + + n_channels = g_value_get_int (value); + value = g_value_array_get_nth (image_struct, 6); + + if (value == NULL) + { + g_warning ("_notify_daemon_pixbuf_from_data_hint expected position 6 of the GValueArray to exist"); + return NULL; + } + + if (!G_VALUE_HOLDS (value, dbus_g_type_get_collection ("GArray", G_TYPE_UCHAR))) + { + g_warning ("_notify_daemon_pixbuf_from_data_hint expected position 6 of the GValueArray to be of type GArray"); + return NULL; + } + + tmp_array = (GArray*) g_value_get_boxed(value); + expected_len = (height - 1) * rowstride + width * ((n_channels * bits_per_sample + 7) / 8); + + if (expected_len != tmp_array->len) + { + g_warning("_notify_daemon_pixbuf_from_data_hint expected image data to be of length %" G_GSIZE_FORMAT " but got a " "length of %u", expected_len, tmp_array->len); + return NULL; + } + + data = (guchar *) g_memdup(tmp_array->data, tmp_array->len); + pixbuf = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, has_alpha, bits_per_sample, width, height, rowstride, (GdkPixbufDestroyNotify) g_free, NULL); + + return pixbuf; +} + +static GdkPixbuf* _notify_daemon_pixbuf_from_path(const char* path) +{ + GdkPixbuf* pixbuf = NULL; + + if (!strncmp (path, "file://", 7) || *path == '/') + { + if (!strncmp (path, "file://", 7)) + { + path += 7; + } + + /* Load file */ + pixbuf = gdk_pixbuf_new_from_file (path, NULL); + } + else + { + /* Load icon theme icon */ + GtkIconTheme *theme; + GtkIconInfo *icon_info; + + theme = gtk_icon_theme_get_default (); + icon_info = gtk_icon_theme_lookup_icon (theme, path, IMAGE_SIZE, GTK_ICON_LOOKUP_USE_BUILTIN); + + if (icon_info != NULL) + { + gint icon_size; + + icon_size = MIN (IMAGE_SIZE, gtk_icon_info_get_base_size (icon_info)); + + if (icon_size == 0) + { + icon_size = IMAGE_SIZE; + } + + pixbuf = gtk_icon_theme_load_icon (theme, path, icon_size, GTK_ICON_LOOKUP_USE_BUILTIN, NULL); + + gtk_icon_info_free (icon_info); + } + + if (pixbuf == NULL) + { + /* Well... maybe this is a file afterall. */ + pixbuf = gdk_pixbuf_new_from_file (path, NULL); + } + } + + return pixbuf; +} + +static void window_clicked_cb(GtkWindow* nw, GdkEventButton* button, NotifyDaemon* daemon) +{ + if (daemon->priv->url_clicked_lock) + { + daemon->priv->url_clicked_lock = FALSE; + return; + } + + _action_invoked_cb (nw, "default"); + _close_notification (daemon, NW_GET_NOTIFY_ID (nw), TRUE, NOTIFYD_CLOSED_USER); +} + +static void url_clicked_cb(GtkWindow* nw, const char *url) +{ + NotifyDaemon* daemon; + char* escaped_url; + char* cmd = NULL; + + daemon = NW_GET_DAEMON(nw); + + /* Somewhat of a hack.. */ + daemon->priv->url_clicked_lock = TRUE; + + escaped_url = g_shell_quote (url); + + if (g_find_program_in_path ("gvfs-open") != NULL) + { + cmd = g_strdup_printf ("gvfs-open %s", escaped_url); + } + else if (g_find_program_in_path ("xdg-open") != NULL) + { + cmd = g_strdup_printf ("xdg-open %s", escaped_url); + } + else if (g_find_program_in_path ("firefox") != NULL) + { + cmd = g_strdup_printf ("firefox %s", escaped_url); + } + else + { + g_warning ("Unable to find a browser."); + } + + g_free (escaped_url); + + if (cmd != NULL) + { + g_spawn_command_line_async (cmd, NULL); + g_free (cmd); + } +} + +static gboolean screensaver_active(GtkWidget* nw) +{ + GError* error = NULL; + gboolean active = FALSE; + + DBusGConnection* connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); + + if (connection == NULL) + { + //g_warning("Failed to get dbus connection: %s", error->message); + g_error_free(error); + goto out; + } + + DBusGProxy* gs_proxy = dbus_g_proxy_new_for_name(connection, "org.mate.ScreenSaver", "/", "org.mate.ScreenSaver"); + + if (!dbus_g_proxy_call(gs_proxy, "GetActive", &error, G_TYPE_INVALID, G_TYPE_BOOLEAN, &active, G_TYPE_INVALID)) + { + //g_warning("Failed to call mate-screensaver: %s", error->message); + g_error_free(error); + } + + g_object_unref(gs_proxy); + + out: + + return active; +} + +static gboolean fullscreen_window_exists(GtkWidget* nw) +{ + WnckScreen* wnck_screen; + WnckWorkspace* wnck_workspace; + GList* l; + + #if (GDK_PIXBUF_MAJOR == 2) && (DK_PIXBUF_MINOR < 22) + wnck_screen = wnck_screen_get(GDK_SCREEN_XNUMBER(gdk_window_get_screen(gtk_widget_get_window(nw)))); + #else + wnck_screen = wnck_screen_get(GDK_SCREEN_XNUMBER(gdk_drawable_get_screen(GDK_DRAWABLE(GTK_WIDGET(nw)->window)))); + #endif + + wnck_screen_force_update (wnck_screen); + + wnck_workspace = wnck_screen_get_active_workspace (wnck_screen); + + for (l = wnck_screen_get_windows_stacked (wnck_screen); l != NULL; l = l->next) + { + WnckWindow *wnck_win = (WnckWindow *) l->data; + + if (wnck_window_is_on_workspace (wnck_win, wnck_workspace) && wnck_window_is_fullscreen (wnck_win) && wnck_window_is_active (wnck_win)) + { + /* + * Sanity check if the window is _really_ fullscreen to + * work around a bug in libwnck that doesn't get all + * unfullscreen events. + */ + int sw = wnck_screen_get_width (wnck_screen); + int sh = wnck_screen_get_height (wnck_screen); + int x, y, w, h; + + wnck_window_get_geometry (wnck_win, &x, &y, &w, &h); + + if (sw == w && sh == h) + { + return TRUE; + } + } + } + + return FALSE; +} + +static Window get_window_parent(Display* display, Window window, Window* root) +{ + Window parent; + Window* children = NULL; + guint nchildren; + gboolean result; + + gdk_error_trap_push(); + result = XQueryTree(display, window, root, &parent, &children, &nchildren); + + if (gdk_error_trap_pop() || !result) + { + return None; + } + + if (children) + { + XFree(children); + } + + return parent; +} + +/* + * Recurse over X Window and parents, up to root, and start watching them + * for position changes. + */ +static void monitor_notification_source_windows(NotifyDaemon *daemon, NotifyTimeout *nt, Window source) +{ + Display* display; + Window root = None; + Window parent; + + display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); + + /* Start monitoring events if necessary. We don't want to + filter events unless we absolutely have to. */ + if (g_hash_table_size (daemon->priv->monitored_window_hash) == 0) + { + gdk_window_add_filter (NULL, (GdkFilterFunc) _notify_x11_filter, daemon); + } + + /* Store the window in the timeout */ + g_assert (nt != NULL); + nt->src_window_xid = source; + + for (parent = get_window_parent (display, source, &root); parent != None && root != parent; parent = get_window_parent (display, parent, &root)) + { + XSelectInput (display, parent, StructureNotifyMask); + + g_hash_table_insert(daemon->priv->monitored_window_hash, GUINT_TO_POINTER (parent), GINT_TO_POINTER (nt->id)); + } +} + +/* Use a source X Window ID to reposition a notification. */ +static void sync_notification_position(NotifyDaemon* daemon, GtkWindow* nw, Window source) +{ + Display* display; + Status result; + Window root; + Window child; + int x, y; + unsigned int width, height; + unsigned int border_width, depth; + + display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default ()); + + gdk_error_trap_push(); + + /* Get the root for this window */ + result = XGetGeometry(display, source, &root, &x, &y, &width, &height, &border_width, &depth); + + if (gdk_error_trap_pop () || !result) + { + return; + } + + /* + * Now calculate the offset coordinates for the source window from + * the root. + */ + gdk_error_trap_push (); + result = XTranslateCoordinates (display, source, root, 0, 0, &x, &y, &child); + if (gdk_error_trap_pop () || !result) + { + return; + } + + x += width / 2; + y += height / 2; + + theme_set_notification_arrow (nw, TRUE, x, y); + theme_move_notification (nw, x, y); + theme_show_notification (nw); + + /* + * We need to manually queue a draw here as the default theme recalculates + * its position in the draw handler and moves the window (which seems + * fairly broken), so just calling move/show above isn't enough to cause + * its position to be calculated. + */ + gtk_widget_queue_draw (GTK_WIDGET (nw)); +} + +GQuark notify_daemon_error_quark(void) +{ + static GQuark q = 0; + + if (q == 0) + { + q = g_quark_from_static_string ("notification-daemon-error-quark"); + } + + return q; +} + +gboolean notify_daemon_notify_handler(NotifyDaemon* daemon, const char* app_name, guint id, const char* icon, const char* summary, const char* body, char** actions, GHashTable* hints, int timeout, DBusGMethodInvocation* context) +{ + NotifyDaemonPrivate *priv = daemon->priv; + NotifyTimeout* nt = NULL; + GtkWindow* nw = NULL; + GValue* data; + gboolean use_pos_data = FALSE; + gboolean new_notification = FALSE; + gint x = 0; + gint y = 0; + Window window_xid = None; + guint return_id; + char* sender; + char* sound_file = NULL; + gboolean sound_enabled; + gint i; + GdkPixbuf* pixbuf; + MateConfClient* mateconf_client; + + if (g_hash_table_size (priv->notification_hash) > MAX_NOTIFICATIONS) + { + GError *error; + + error = g_error_new (notify_daemon_error_quark (), 1, _("Exceeded maximum number of notifications")); + dbus_g_method_return_error (context, error); + g_error_free (error); + + return TRUE; + } + + if (id > 0) + { + nt = (NotifyTimeout *) g_hash_table_lookup (priv->notification_hash, &id); + + if (nt != NULL) + { + nw = nt->nw; + } + else + { + id = 0; + } + } + + if (nw == NULL) + { + nw = theme_create_notification (url_clicked_cb); + g_object_set_data (G_OBJECT (nw), "_notify_daemon", daemon); + gtk_widget_realize (GTK_WIDGET (nw)); + new_notification = TRUE; + + g_signal_connect (G_OBJECT (nw), "button-release-event", G_CALLBACK (window_clicked_cb), daemon); + g_signal_connect (G_OBJECT (nw), "destroy", G_CALLBACK (_notification_destroyed_cb), daemon); + g_signal_connect (G_OBJECT (nw), "enter-notify-event", G_CALLBACK (_mouse_entered_cb), daemon); + g_signal_connect (G_OBJECT (nw), "leave-notify-event", G_CALLBACK (_mouse_exitted_cb), daemon); + } + else + { + theme_clear_notification_actions (nw); + } + + theme_set_notification_text (nw, summary, body); + theme_set_notification_hints (nw, hints); + + /* + *XXX This needs to handle file URIs and all that. + */ + + + if ((data = (GValue *) g_hash_table_lookup (hints, "window-xid")) != NULL) + { + window_xid = (Window) g_value_get_uint (data); + } + /* deal with x, and y hints */ + else if ((data = (GValue *) g_hash_table_lookup (hints, "x")) != NULL) + { + x = g_value_get_int (data); + + if ((data = (GValue *) g_hash_table_lookup (hints, "y")) != NULL) + { + y = g_value_get_int (data); + use_pos_data = TRUE; + } + } + + /* Deal with sound hints */ + mateconf_client = mateconf_client_get_default (); + sound_enabled = mateconf_client_get_bool (mateconf_client, MATECONF_KEY_SOUND_ENABLED, NULL); + g_object_unref (mateconf_client); + + data = (GValue *) g_hash_table_lookup (hints, "suppress-sound"); + + if (data != NULL) + { + if (G_VALUE_HOLDS_BOOLEAN (data)) + { + sound_enabled = !g_value_get_boolean (data); + } + else if (G_VALUE_HOLDS_INT (data)) + { + sound_enabled = (g_value_get_int (data) != 0); + } + else + { + g_warning ("suppress-sound is of type %s (expected bool or int)\n", g_type_name (G_VALUE_TYPE (data))); + } + } + + if (sound_enabled) + { + data = (GValue *) g_hash_table_lookup (hints, "sound-file"); + + if (data != NULL) + { + sound_file = g_value_dup_string (data); + + if (*sound_file == '\0' || !g_file_test (sound_file, G_FILE_TEST_EXISTS)) + { + g_free (sound_file); + sound_file = NULL; + } + } + } + + /* set up action buttons */ + for (i = 0; actions[i] != NULL; i += 2) + { + char* l = actions[i + 1]; + + if (l == NULL) + { + g_warning ("Label not found for action %s. The protocol specifies that a label must follow an action in the actions array", actions[i]); + + break; + } + + if (strcasecmp (actions[i], "default")) + { + theme_add_notification_action (nw, l, actions[i], G_CALLBACK (_action_invoked_cb)); + } + } + + pixbuf = NULL; + + if ((data = (GValue *) g_hash_table_lookup (hints, "image_data"))) + { + pixbuf = _notify_daemon_pixbuf_from_data_hint (data); + } + else if ((data = (GValue *) g_hash_table_lookup (hints, "image_path"))) + { + if (G_VALUE_HOLDS_STRING (data)) + { + const char *path = g_value_get_string (data); + pixbuf = _notify_daemon_pixbuf_from_path (path); + } + else + { + g_warning ("notify_daemon_notify_handler expected image_path hint to be of type string"); + } + } + else if (*icon != '\0') + { + pixbuf = _notify_daemon_pixbuf_from_path (icon); + } + else if ((data = (GValue *) g_hash_table_lookup (hints, "icon_data"))) + { + g_warning("\"icon_data\" hint is deprecated, please use \"image_data\" instead"); + pixbuf = _notify_daemon_pixbuf_from_data_hint (data); + } + + if (pixbuf != NULL) + { + theme_set_notification_icon (nw, pixbuf); + g_object_unref (G_OBJECT (pixbuf)); + } + + if (window_xid != None && !theme_get_always_stack (nw)) + { + /* + * Do nothing here if we were passed an XID; we'll call + * sync_notification_position later. + */ + } + else if (use_pos_data && !theme_get_always_stack (nw)) + { + /* + * Typically, the theme engine will set its own position based on + * the arrow X, Y hints. However, in case, move the notification to + * that position. + */ + theme_set_notification_arrow (nw, TRUE, x, y); + theme_move_notification (nw, x, y); + } + else + { + int monitor_num; + int screen_num; + GdkScreen* screen; + gint x, y; + + theme_set_notification_arrow (nw, FALSE, 0, 0); + + gdk_display_get_pointer (gdk_display_get_default (), &screen, &x, &y, NULL); + screen_num = gdk_screen_get_number (screen); + monitor_num = gdk_screen_get_monitor_at_point (screen, x, y); + + if (monitor_num >= priv->screens[screen_num]->n_stacks) + { + /* screw it - dump it on the last one we'll get + a monitors-changed signal soon enough*/ + monitor_num = priv->screens[screen_num]->n_stacks - 1; + } + + notify_stack_add_window (priv->screens[screen_num]->stacks[monitor_num], nw, new_notification); + } + + if (id == 0) + { + nt = _store_notification (daemon, nw, timeout); + return_id = nt->id; + } + else + { + return_id = id; + } + + /* + * If we have a source Window XID, start monitoring the tree + * for changes, and reposition the window based on the source + * window. We need to do this after return_id is calculated. + */ + if (window_xid != None && !theme_get_always_stack (nw)) + { + monitor_notification_source_windows (daemon, nt, window_xid); + sync_notification_position (daemon, nw, window_xid); + } + + if (!screensaver_active (GTK_WIDGET (nw)) && !fullscreen_window_exists (GTK_WIDGET (nw))) + { + theme_show_notification (nw); + + if (sound_file != NULL) + { + sound_play_file (GTK_WIDGET (nw), sound_file); + } + } + else + { + _NotifyPendingClose* data; + + /* The notification was not shown, so queue up a close + * for it */ + data = g_new0 (_NotifyPendingClose, 1); + data->id = id; + data->daemon = g_object_ref (daemon); + g_idle_add ((GSourceFunc) _close_notification_not_shown, data); + } + + g_free (sound_file); + + sender = dbus_g_method_get_sender (context); + + g_object_set_data (G_OBJECT (nw), "_notify_id", GUINT_TO_POINTER (return_id)); + g_object_set_data_full (G_OBJECT (nw), "_notify_sender", sender, (GDestroyNotify) g_free); + + if (nt) + { + _calculate_timeout (daemon, nt, timeout); + } + + dbus_g_method_return (context, return_id); + + return TRUE; +} + +gboolean notify_daemon_close_notification_handler(NotifyDaemon* daemon, guint id, GError** error) +{ + if (id == 0) + { + g_set_error (error, notify_daemon_error_quark (), 100, _("%u is not a valid notification ID"), id); + return FALSE; + } + else + { + _close_notification (daemon, id, TRUE, NOTIFYD_CLOSED_API); + return TRUE; + } +} + +gboolean notify_daemon_get_capabilities(NotifyDaemon* daemon, char*** caps) +{ + GPtrArray* a = g_ptr_array_new (); + g_ptr_array_add (a, g_strdup ("actions")); + g_ptr_array_add (a, g_strdup ("body")); + g_ptr_array_add (a, g_strdup ("body-hyperlinks")); + g_ptr_array_add (a, g_strdup ("body-markup")); + g_ptr_array_add (a, g_strdup ("icon-static")); + g_ptr_array_add (a, g_strdup ("sound")); + g_ptr_array_add (a, NULL); + char** _caps = (char**) g_ptr_array_free (a, FALSE); + + *caps = _caps; + + return TRUE; +} + +gboolean notify_daemon_get_server_information(NotifyDaemon *daemon, char** out_name, char** out_vendor, char** out_version, char** out_spec_ver) +{ + *out_name = g_strdup("Notification Daemon"); + *out_vendor = g_strdup("MATE"); + *out_version = g_strdup(PACKAGE_VERSION); + *out_spec_ver = g_strdup("1.1"); + + return TRUE; +} + +int main(int argc, char** argv) +{ + NotifyDaemon* daemon; + DBusGConnection* connection; + DBusGProxy* bus_proxy; + GError* error; + gboolean res; + guint request_name_result; + + g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL); + + gtk_init(&argc, &argv); + + error = NULL; + connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); + + if (connection == NULL) + { + g_printerr("Failed to open connection to bus: %s\n", error->message); + g_error_free(error); + exit(1); + } + + dbus_conn = dbus_g_connection_get_connection(connection); + + dbus_g_object_type_install_info(NOTIFY_TYPE_DAEMON, &dbus_glib_notification_daemon_object_info); + + bus_proxy = dbus_g_proxy_new_for_name(connection, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus"); + + res = dbus_g_proxy_call(bus_proxy, "RequestName", &error, G_TYPE_STRING, NOTIFICATION_BUS_NAME, G_TYPE_UINT, 0, G_TYPE_INVALID, G_TYPE_UINT, &request_name_result, G_TYPE_INVALID); + + if (! res || request_name_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) + { + if (error != NULL) + { + g_warning("Failed to acquire name %s: %s", NOTIFICATION_BUS_NAME, error->message); + g_error_free(error); + } + else + { + g_warning("Failed to acquire name %s", NOTIFICATION_BUS_NAME); + } + + goto out; + } + + daemon = g_object_new(NOTIFY_TYPE_DAEMON, NULL); + + dbus_g_connection_register_g_object(connection, "/org/freedesktop/Notifications", G_OBJECT(daemon)); + + gtk_main(); + + g_object_unref(daemon); + + out: + + return 0; +} diff --git a/src/daemon/daemon.h b/src/daemon/daemon.h new file mode 100644 index 0000000..7f815c7 --- /dev/null +++ b/src/daemon/daemon.h @@ -0,0 +1,103 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * Copyright (C) 2006 Christian Hammond + * Copyright (C) 2005 John (J5) Palmieri + * Copyright (C) 2010 Red Hat, Inc. + * Copyright (C) 2011 Perberos + * + * 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; either version 2, or (at your option) + * any later version. + * + * 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. + */ + +#ifndef NOTIFY_DAEMON_H +#define NOTIFY_DAEMON_H + +#include +#include +#include + +#include +#include + +#define MATECONF_KEY_DAEMON "/apps/mate-notification-daemon" +#define MATECONF_KEY_THEME MATECONF_KEY_DAEMON "/theme" +#define MATECONF_KEY_POPUP_LOCATION MATECONF_KEY_DAEMON "/popup_location" +#define MATECONF_KEY_SOUND_ENABLED MATECONF_KEY_DAEMON "/sound_enabled" +#define MATECONF_KEY_DEFAULT_SOUND MATECONF_KEY_DAEMON "/default_sound" + +#define NOTIFY_TYPE_DAEMON (notify_daemon_get_type()) +#define NOTIFY_DAEMON(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), NOTIFY_TYPE_DAEMON, NotifyDaemon)) +#define NOTIFY_DAEMON_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), NOTIFY_TYPE_DAEMON, NotifyDaemonClass)) +#define NOTIFY_IS_DAEMON(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NOTIFY_TYPE_DAEMON)) +#define NOTIFY_IS_DAEMON_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), NOTIFY_TYPE_DAEMON)) +#define NOTIFY_DAEMON_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), NOTIFY_TYPE_DAEMON, NotifyDaemonClass)) + +#define NOTIFY_DAEMON_DEFAULT_TIMEOUT 7000 + +enum { + URGENCY_LOW, + URGENCY_NORMAL, + URGENCY_CRITICAL +}; + +typedef enum { + NOTIFYD_CLOSED_EXPIRED = 1, + NOTIFYD_CLOSED_USER = 2, + NOTIFYD_CLOSED_API = 3, + NOTIFYD_CLOSED_RESERVED = 4 +} NotifydClosedReason; + +typedef struct _NotifyDaemon NotifyDaemon; +typedef struct _NotifyDaemonClass NotifyDaemonClass; +typedef struct _NotifyDaemonPrivate NotifyDaemonPrivate; + +struct _NotifyDaemon { + GObject parent; + + /*< private > */ + NotifyDaemonPrivate* priv; +}; + +struct _NotifyDaemonClass { + GObjectClass parent_class; +}; + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +GType notify_daemon_get_type(void); + +GQuark notify_daemon_error_quark(void); + +gboolean notify_daemon_notify_handler(NotifyDaemon* daemon, const gchar* app_name, guint id, const gchar* icon, const gchar* summary, const gchar* body, gchar** actions, GHashTable* hints, int timeout, DBusGMethodInvocation* context); + +gboolean notify_daemon_close_notification_handler(NotifyDaemon* daemon, guint id, GError** error); + +gboolean notify_daemon_get_capabilities(NotifyDaemon* daemon, char*** out_caps); + +gboolean notify_daemon_get_server_information(NotifyDaemon* daemon, char** out_name, char** out_vendor, char** out_version, char** out_spec_ver); + +MateConfClient* get_mateconf_client(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* NOTIFY_DAEMON_H */ diff --git a/src/daemon/engines.c b/src/daemon/engines.c new file mode 100644 index 0000000..4426275 --- /dev/null +++ b/src/daemon/engines.c @@ -0,0 +1,338 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * Copyright (C) 2006 Christian Hammond + * Copyright (C) 2005 John (J5) Palmieri + * Copyright (C) 2010 Red Hat, Inc. + * Copyright (C) 2011 Perberos + * + * 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; either version 2, or (at your option) + * any later version. + * + * 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. + */ + +#include "config.h" + +#include +#include "daemon.h" +#include "engines.h" + +typedef struct { + GModule* module; + guint ref_count; + + /* callbacks */ + gboolean (*theme_check_init) (unsigned int major_ver, unsigned int minor_ver, unsigned int micro_ver); + void (*get_theme_info) (char** theme_name, char** theme_ver, char** author, char** homepage); + GtkWindow* (*create_notification) (UrlClickedCb url_clicked_cb); + void (*destroy_notification) (GtkWindow* nw); + void (*show_notification) (GtkWindow* nw); + void (*hide_notification) (GtkWindow* nw); + void (*set_notification_hints) (GtkWindow* nw, GHashTable* hints); + void (*set_notification_text) (GtkWindow* nw, const char* summary, const char* body); + void (*set_notification_icon) (GtkWindow* nw, GdkPixbuf* pixbuf); + void (*set_notification_arrow) (GtkWindow* nw, gboolean visible, int x, int y); + void (*add_notification_action) (GtkWindow* nw, const char* label, const char* key, GCallback cb); + void (*clear_notification_actions) (GtkWindow* nw); + void (*move_notification) (GtkWindow* nw, int x, int y); + void (*set_notification_timeout) (GtkWindow* nw, glong timeout); + void (*notification_tick) (GtkWindow* nw, glong timeout); + gboolean (*get_always_stack) (GtkWindow* nw); + +} ThemeEngine; + +static guint theme_prop_notify_id = 0; +static ThemeEngine* active_engine = NULL; + +static ThemeEngine* load_theme_engine(const char *name) +{ + ThemeEngine* engine; + char* filename; + char* path; + + filename = g_strdup_printf("lib%s.so", name); + path = g_build_filename(ENGINES_DIR, filename, NULL); + g_free (filename); + + engine = g_new0(ThemeEngine, 1); + engine->ref_count = 1; + engine->module = g_module_open(path, G_MODULE_BIND_LAZY); + + g_free(path); + + if (engine->module == NULL) + goto error; + + #define BIND_REQUIRED_FUNC(name) \ + if (!g_module_symbol(engine->module, #name, (gpointer*) &engine->name)) \ + { \ + /* Too harsh! Fall back to default. */ \ + g_warning("Theme doesn't provide the required function '%s'", #name); \ + goto error; \ + } + + #define BIND_OPTIONAL_FUNC(name) \ + g_module_symbol(engine->module, #name, (gpointer*) &engine->name); + + BIND_REQUIRED_FUNC(theme_check_init); + BIND_REQUIRED_FUNC(get_theme_info); + BIND_REQUIRED_FUNC(create_notification); + BIND_REQUIRED_FUNC(set_notification_text); + BIND_REQUIRED_FUNC(set_notification_icon); + BIND_REQUIRED_FUNC(set_notification_arrow); + BIND_REQUIRED_FUNC(add_notification_action); + BIND_REQUIRED_FUNC(clear_notification_actions); + BIND_REQUIRED_FUNC(move_notification); + + BIND_OPTIONAL_FUNC(destroy_notification); + BIND_OPTIONAL_FUNC(show_notification); + BIND_OPTIONAL_FUNC(hide_notification); + BIND_OPTIONAL_FUNC(set_notification_timeout); + BIND_OPTIONAL_FUNC(set_notification_hints); + BIND_OPTIONAL_FUNC(notification_tick); + BIND_OPTIONAL_FUNC(get_always_stack); + + if (!engine->theme_check_init(NOTIFICATION_DAEMON_MAJOR_VERSION, NOTIFICATION_DAEMON_MINOR_VERSION, NOTIFICATION_DAEMON_MICRO_VERSION)) + { + g_warning ("Theme doesn't work with this version of mate-notification-daemon"); + goto error; + } + + return engine; + + error: + + if (engine->module != NULL && !g_module_close (engine->module)) + { + g_warning("%s: %s", filename, g_module_error()); + } + + g_free(engine); + return NULL; +} + +static void destroy_engine(ThemeEngine* engine) +{ + g_assert(engine->ref_count == 0); + + if (active_engine == engine) + active_engine = NULL; + + g_module_close(engine->module); + g_free(engine); +} + +static gboolean theme_engine_destroy(ThemeEngine* engine) +{ + destroy_engine(engine); + return FALSE; +} + +static void theme_engine_unref(ThemeEngine* engine) +{ + engine->ref_count--; + + if (engine->ref_count == 0) + { + /* + * Destroy the engine in an idle loop since the last reference + * might have been the one of a notification which is being + * destroyed and that still has references to the engine + * module. This way, we're sure the notification is completely + * destroyed before the engine is. + */ + g_idle_add((GSourceFunc) theme_engine_destroy, engine); + } +} + +static void theme_changed_cb(MateConfClient* client, guint cnxn_id, MateConfEntry* entry, gpointer user_data) +{ + if (active_engine == NULL) + { + return; + } + + theme_engine_unref(active_engine); + + /* This is no longer the true active engine, so reset this. */ + active_engine = NULL; +} + +static ThemeEngine* get_theme_engine(void) +{ + if (active_engine == NULL) + { + MateConfClient* client = mateconf_client_get_default(); + char* enginename = mateconf_client_get_string(client, MATECONF_KEY_THEME, NULL); + + if (theme_prop_notify_id == 0) + { + theme_prop_notify_id = mateconf_client_notify_add(client, MATECONF_KEY_THEME, theme_changed_cb, NULL, NULL, NULL); + } + + g_object_unref(client); + + if (enginename == NULL) + { + active_engine = load_theme_engine("standard"); + g_assert(active_engine != NULL); + } + else + { + active_engine = load_theme_engine(enginename); + + if (active_engine == NULL) + { + g_warning("Unable to load theme engine '%s'", enginename); + active_engine = load_theme_engine("standard"); + } + + g_free(enginename); + + g_assert(active_engine != NULL); + } + } + + return active_engine; +} + +GtkWindow* theme_create_notification(UrlClickedCb url_clicked_cb) +{ + ThemeEngine* engine = get_theme_engine(); + GtkWindow* nw = engine->create_notification(url_clicked_cb); + g_object_set_data_full(G_OBJECT(nw), "_theme_engine", engine, (GDestroyNotify) theme_engine_unref); + engine->ref_count++; + return nw; +} + +void theme_destroy_notification(GtkWindow* nw) +{ + ThemeEngine* engine = g_object_get_data(G_OBJECT(nw), "_theme_engine"); + + if (engine->destroy_notification != NULL) + { + engine->destroy_notification(nw); + } + else + { + gtk_widget_destroy(GTK_WIDGET(nw)); + } +} + +void theme_show_notification(GtkWindow* nw) +{ + ThemeEngine *engine = g_object_get_data(G_OBJECT(nw), "_theme_engine"); + + if (engine->show_notification != NULL) + { + engine->show_notification(nw); + } + else + { + gtk_widget_show(GTK_WIDGET(nw)); + } +} + +void theme_hide_notification(GtkWindow* nw) +{ + ThemeEngine* engine = g_object_get_data(G_OBJECT(nw), "_theme_engine"); + + if (engine->hide_notification != NULL) + { + engine->hide_notification(nw); + } + else + { + gtk_widget_hide(GTK_WIDGET(nw)); + } +} + +void theme_set_notification_hints(GtkWindow* nw, GHashTable* hints) +{ + ThemeEngine* engine = g_object_get_data(G_OBJECT(nw), "_theme_engine"); + + if (engine->set_notification_hints != NULL) + { + engine->set_notification_hints(nw, hints); + } +} + +void theme_set_notification_timeout(GtkWindow* nw, glong timeout) +{ + ThemeEngine* engine = g_object_get_data(G_OBJECT(nw), "_theme_engine"); + + if (engine->set_notification_timeout != NULL) + { + engine->set_notification_timeout(nw, timeout); + } +} + +void theme_notification_tick(GtkWindow* nw, glong remaining) +{ + ThemeEngine* engine = g_object_get_data(G_OBJECT(nw), "_theme_engine"); + + if (engine->notification_tick != NULL) + { + engine->notification_tick(nw, remaining); + } +} + +void theme_set_notification_text(GtkWindow* nw, const char* summary, const char* body) +{ + ThemeEngine* engine = g_object_get_data(G_OBJECT (nw), "_theme_engine"); + engine->set_notification_text (nw, summary, body); +} + +void theme_set_notification_icon(GtkWindow* nw, GdkPixbuf* pixbuf) +{ + ThemeEngine* engine = g_object_get_data(G_OBJECT (nw), "_theme_engine"); + engine->set_notification_icon(nw, pixbuf); +} + +void theme_set_notification_arrow(GtkWindow* nw, gboolean visible, int x, int y) +{ + ThemeEngine* engine = g_object_get_data(G_OBJECT (nw), "_theme_engine"); + engine->set_notification_arrow(nw, visible, x, y); +} + +void theme_add_notification_action(GtkWindow* nw, const char* label, const char* key, GCallback cb) +{ + ThemeEngine* engine = g_object_get_data(G_OBJECT(nw), "_theme_engine"); + engine->add_notification_action(nw, label, key, cb); +} + +void theme_clear_notification_actions(GtkWindow* nw) +{ + ThemeEngine* engine = g_object_get_data(G_OBJECT(nw), "_theme_engine"); + engine->clear_notification_actions(nw); +} + +void theme_move_notification(GtkWindow* nw, int x, int y) +{ + ThemeEngine* engine = g_object_get_data(G_OBJECT(nw), "_theme_engine"); + engine->move_notification(nw, x, y); +} + +gboolean theme_get_always_stack(GtkWindow* nw) +{ + ThemeEngine* engine = g_object_get_data(G_OBJECT(nw), "_theme_engine"); + + if (engine->get_always_stack != NULL) + { + return engine->get_always_stack(nw); + } + else + { + return FALSE; + } +} diff --git a/src/daemon/engines.h b/src/daemon/engines.h new file mode 100644 index 0000000..e5ffa49 --- /dev/null +++ b/src/daemon/engines.h @@ -0,0 +1,60 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * Copyright (C) 2006 Christian Hammond + * Copyright (C) 2005 John (J5) Palmieri + * Copyright (C) 2010 Red Hat, Inc. + * Copyright (C) 2011 Perberos + * + * 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; either version 2, or (at your option) + * any later version. + * + * 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. + */ + +#ifndef _ENGINES_H_ +#define _ENGINES_H_ + +#include + +typedef void (*UrlClickedCb) (GtkWindow * nw, const char *url); + +GtkWindow *theme_create_notification (UrlClickedCb url_clicked_cb); +void theme_destroy_notification (GtkWindow *nw); +void theme_show_notification (GtkWindow *nw); +void theme_hide_notification (GtkWindow *nw); +void theme_set_notification_hints (GtkWindow *nw, + GHashTable *hints); +void theme_set_notification_timeout (GtkWindow *nw, + glong timeout); +void theme_notification_tick (GtkWindow *nw, + glong remaining); +void theme_set_notification_text (GtkWindow *nw, + const char *summary, + const char *body); +void theme_set_notification_icon (GtkWindow *nw, + GdkPixbuf *pixbuf); +void theme_set_notification_arrow (GtkWindow *nw, + gboolean visible, + int x, + int y); +void theme_add_notification_action (GtkWindow *nw, + const char *label, + const char *key, + GCallback cb); +void theme_clear_notification_actions (GtkWindow *nw); +void theme_move_notification (GtkWindow *nw, + int x, + int y); +gboolean theme_get_always_stack (GtkWindow *nw); + +#endif /* _ENGINES_H_ */ diff --git a/src/daemon/notificationdaemon.xml b/src/daemon/notificationdaemon.xml new file mode 100644 index 0000000..e16979f --- /dev/null +++ b/src/daemon/notificationdaemon.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/daemon/sound.c b/src/daemon/sound.c new file mode 100644 index 0000000..6dbf30f --- /dev/null +++ b/src/daemon/sound.c @@ -0,0 +1,39 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * Copyright (C) 2007 Jim Ramsay + * Copyright (C) 2011 Perberos + * + * 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; either version 2, or (at your option) + * any later version. + * + * 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. + */ + +#include "config.h" + +#include "sound.h" + +#include +#include + +void +sound_play_file (GtkWidget *widget, + const char *filename) +{ + ca_gtk_play_for_widget (widget, 0, + CA_PROP_MEDIA_ROLE, "event", + CA_PROP_MEDIA_FILENAME, filename, + CA_PROP_EVENT_DESCRIPTION, _("Notification"), + NULL); +} + diff --git a/src/daemon/sound.h b/src/daemon/sound.h new file mode 100644 index 0000000..1642382 --- /dev/null +++ b/src/daemon/sound.h @@ -0,0 +1,29 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * Copyright (C) 2007 Jim Ramsay + * Copyright (C) 2011 Perberos + * + * 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; either version 2, or (at your option) + * any later version. + * + * 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. + */ + +#ifndef _SOUND_H +#define _SOUND_H + +#include + +void sound_play_file(GtkWidget* widget, const char* filename); + +#endif /* _SOUND_H */ diff --git a/src/daemon/stack.c b/src/daemon/stack.c new file mode 100644 index 0000000..95b50da --- /dev/null +++ b/src/daemon/stack.c @@ -0,0 +1,409 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * Copyright (C) 2006 Christian Hammond + * Copyright (C) 2010 Red Hat, Inc. + * Copyright (C) 2011 Perberos + * + * 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; either version 2, or (at your option) + * any later version. + * + * 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. + */ + +#include "config.h" +#include "engines.h" +#include "stack.h" + +#include +#include +#include +#include +#include + +#define NOTIFY_STACK_SPACING 2 +#define WORKAREA_PADDING 6 + +struct _NotifyStack { + NotifyDaemon* daemon; + GdkScreen* screen; + guint monitor; + NotifyStackLocation location; + GList* windows; + guint update_id; +}; + +GList* notify_stack_get_windows(NotifyStack *stack) +{ + return stack->windows; +} + +static gboolean +get_work_area (NotifyStack *stack, + GdkRectangle *rect) +{ + Atom workarea; + Atom type; + Window win; + int format; + gulong num; + gulong leftovers; + gulong max_len = 4 * 32; + guchar *ret_workarea; + long *workareas; + int result; + int disp_screen; + + #if GTK_CHECK_VERSION(3, 0, 0) + workarea = XInternAtom(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "_NET_WORKAREA", True); + #else + workarea = XInternAtom(GDK_DISPLAY(), "_NET_WORKAREA", True); + #endif + + + disp_screen = GDK_SCREEN_XNUMBER (stack->screen); + + /* Defaults in case of error */ + rect->x = 0; + rect->y = 0; + rect->width = gdk_screen_get_width (stack->screen); + rect->height = gdk_screen_get_height (stack->screen); + + if (workarea == None) + return FALSE; + + + #if GTK_CHECK_VERSION(3, 0, 0) + + win = XRootWindow(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), disp_screen); + + result = XGetWindowProperty(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), + win, + workarea, + 0, + max_len, + False, + AnyPropertyType, + &type, + &format, + &num, + &leftovers, + &ret_workarea); + #else + + win = XRootWindow(GDK_DISPLAY(), disp_screen); + + result = XGetWindowProperty(GDK_DISPLAY(), + win, + workarea, + 0, + max_len, + False, + AnyPropertyType, + &type, + &format, + &num, + &leftovers, + &ret_workarea); + #endif + + if (result != Success + || type == None + || format == 0 + || leftovers + || num % 4) { + return FALSE; + } + + workareas = (long *) ret_workarea; + rect->x = workareas[disp_screen * 4]; + rect->y = workareas[disp_screen * 4 + 1]; + rect->width = workareas[disp_screen * 4 + 2]; + rect->height = workareas[disp_screen * 4 + 3]; + + XFree (ret_workarea); + + return TRUE; +} + +static void +get_origin_coordinates (NotifyStackLocation stack_location, + GdkRectangle *workarea, + gint *x, + gint *y, + gint *shiftx, + gint *shifty, + gint width, + gint height) +{ + switch (stack_location) { + case NOTIFY_STACK_LOCATION_TOP_LEFT: + *x = workarea->x; + *y = workarea->y; + *shifty = height; + break; + + case NOTIFY_STACK_LOCATION_TOP_RIGHT: + *x = workarea->x + workarea->width - width; + *y = workarea->y; + *shifty = height; + break; + + case NOTIFY_STACK_LOCATION_BOTTOM_LEFT: + *x = workarea->x; + *y = workarea->y + workarea->height - height; + break; + + case NOTIFY_STACK_LOCATION_BOTTOM_RIGHT: + *x = workarea->x + workarea->width - width; + *y = workarea->y + workarea->height - height; + break; + + default: + g_assert_not_reached (); + } +} + +static void +translate_coordinates (NotifyStackLocation stack_location, + GdkRectangle *workarea, + gint *x, + gint *y, + gint *shiftx, + gint *shifty, + gint width, + gint height) +{ + switch (stack_location) { + case NOTIFY_STACK_LOCATION_TOP_LEFT: + *x = workarea->x; + *y += *shifty; + *shifty = height; + break; + + case NOTIFY_STACK_LOCATION_TOP_RIGHT: + *x = workarea->x + workarea->width - width; + *y += *shifty; + *shifty = height; + break; + + case NOTIFY_STACK_LOCATION_BOTTOM_LEFT: + *x = workarea->x; + *y -= height; + break; + + case NOTIFY_STACK_LOCATION_BOTTOM_RIGHT: + *x = workarea->x + workarea->width - width; + *y -= height; + break; + + default: + g_assert_not_reached (); + } +} + +NotifyStack * +notify_stack_new (NotifyDaemon *daemon, + GdkScreen *screen, + guint monitor, + NotifyStackLocation location) +{ + NotifyStack *stack; + + g_assert (daemon != NULL); + g_assert (screen != NULL && GDK_IS_SCREEN (screen)); + g_assert (monitor < (guint)gdk_screen_get_n_monitors (screen)); + g_assert (location != NOTIFY_STACK_LOCATION_UNKNOWN); + + stack = g_new0 (NotifyStack, 1); + stack->daemon = daemon; + stack->screen = screen; + stack->monitor = monitor; + stack->location = location; + + return stack; +} + +void +notify_stack_destroy (NotifyStack *stack) +{ + g_assert (stack != NULL); + + if (stack->update_id != 0) { + g_source_remove (stack->update_id); + } + + g_list_free (stack->windows); + g_free (stack); +} + +void +notify_stack_set_location (NotifyStack *stack, + NotifyStackLocation location) +{ + stack->location = location; +} + +static void +add_padding_to_rect (GdkRectangle *rect) +{ + rect->x += WORKAREA_PADDING; + rect->y += WORKAREA_PADDING; + rect->width -= WORKAREA_PADDING * 2; + rect->height -= WORKAREA_PADDING * 2; + + if (rect->width < 0) + rect->width = 0; + if (rect->height < 0) + rect->height = 0; +} + +static void +notify_stack_shift_notifications (NotifyStack *stack, + GtkWindow *nw, + GList **nw_l, + gint init_width, + gint init_height, + gint *nw_x, + gint *nw_y) +{ + GdkRectangle workarea; + GdkRectangle monitor; + GdkRectangle *positions; + GList *l; + gint x, y; + gint shiftx = 0; + gint shifty = 0; + int i; + int n_wins; + + get_work_area (stack, &workarea); + gdk_screen_get_monitor_geometry (stack->screen, + stack->monitor, + &monitor); + gdk_rectangle_intersect (&monitor, &workarea, &workarea); + + add_padding_to_rect (&workarea); + + n_wins = g_list_length (stack->windows); + positions = g_new0 (GdkRectangle, n_wins); + + get_origin_coordinates (stack->location, + &workarea, + &x, &y, + &shiftx, + &shifty, + init_width, + init_height); + + if (nw_x != NULL) + *nw_x = x; + + if (nw_y != NULL) + *nw_y = y; + + for (i = 0, l = stack->windows; l != NULL; i++, l = l->next) { + GtkWindow *nw2 = GTK_WINDOW (l->data); + GtkRequisition req; + + if (nw == NULL || nw2 != nw) { + gtk_widget_size_request (GTK_WIDGET (nw2), &req); + + translate_coordinates (stack->location, + &workarea, + &x, + &y, + &shiftx, + &shifty, + req.width, + req.height + NOTIFY_STACK_SPACING); + positions[i].x = x; + positions[i].y = y; + } else if (nw_l != NULL) { + *nw_l = l; + positions[i].x = -1; + positions[i].y = -1; + } + } + + /* move bubbles at the bottom of the stack first + to avoid overlapping */ + for (i = n_wins - 1, l = g_list_last (stack->windows); l != NULL; i--, l = l->prev) { + GtkWindow *nw2 = GTK_WINDOW (l->data); + + if (nw == NULL || nw2 != nw) { + theme_move_notification (nw2, positions[i].x, positions[i].y); + } + } + + g_free (positions); +} + +static void update_position(NotifyStack* stack) +{ + /* notify_stack_shift_notifications(stack, window, list pointer, init width, init height, out window x, out window y) */ + notify_stack_shift_notifications (stack, NULL, NULL, 0, 0, NULL, NULL); +} + +static gboolean update_position_idle(NotifyStack* stack) +{ + update_position(stack); + + stack->update_id = 0; + return FALSE; +} + +void notify_stack_queue_update_position(NotifyStack* stack) +{ + if (stack->update_id != 0) + { + return; + } + + stack->update_id = g_idle_add((GSourceFunc) update_position_idle, stack); +} + +void notify_stack_add_window(NotifyStack* stack, GtkWindow* nw, gboolean new_notification) +{ + GtkRequisition req; + gint x, y; + + gtk_widget_size_request(GTK_WIDGET(nw), &req); + notify_stack_shift_notifications(stack, nw, NULL, req.width, req.height + NOTIFY_STACK_SPACING, &x, &y); + theme_move_notification(nw, x, y); + + if (new_notification) + { + g_signal_connect_swapped(G_OBJECT(nw), "destroy", G_CALLBACK(notify_stack_remove_window), stack); + stack->windows = g_list_prepend(stack->windows, nw); + } +} + +void notify_stack_remove_window(NotifyStack* stack, GtkWindow* nw) +{ + GList* remove_l = NULL; + + notify_stack_shift_notifications(stack, nw, &remove_l, 0, 0, NULL, NULL); + + if (remove_l != NULL) + { + stack->windows = g_list_delete_link(stack->windows, remove_l); + } + + #if GTK_CHECK_VERSION(2, 20, 0) + if (gtk_widget_get_realized(GTK_WIDGET(nw))) + gtk_widget_unrealize(GTK_WIDGET(nw)); + #else + if (GTK_WIDGET_REALIZED(GTK_WIDGET(nw))) + gtk_widget_unrealize(GTK_WIDGET(nw)); + #endif +} diff --git a/src/daemon/stack.h b/src/daemon/stack.h new file mode 100644 index 0000000..b2daafe --- /dev/null +++ b/src/daemon/stack.h @@ -0,0 +1,50 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * Copyright (C) 2006 Christian Hammond + * Copyright (C) 2010 Red Hat, Inc. + * Copyright (C) 2011 Perberos + * + * 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; either version 2, or (at your option) + * any later version. + * + * 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. + */ + +#ifndef _NOTIFY_STACK_H_ +#define _NOTIFY_STACK_H_ + +#include + +#include "daemon.h" + +typedef enum { + NOTIFY_STACK_LOCATION_UNKNOWN = -1, + NOTIFY_STACK_LOCATION_TOP_LEFT, + NOTIFY_STACK_LOCATION_TOP_RIGHT, + NOTIFY_STACK_LOCATION_BOTTOM_LEFT, + NOTIFY_STACK_LOCATION_BOTTOM_RIGHT, + NOTIFY_STACK_LOCATION_DEFAULT = NOTIFY_STACK_LOCATION_BOTTOM_RIGHT +} NotifyStackLocation; + +typedef struct _NotifyStack NotifyStack; + +NotifyStack* notify_stack_new(NotifyDaemon* daemon, GdkScreen* screen, guint monitor, NotifyStackLocation stack_location); +void notify_stack_destroy(NotifyStack* stack); + +void notify_stack_set_location(NotifyStack* stack, NotifyStackLocation location); +void notify_stack_add_window(NotifyStack* stack, GtkWindow* nw, gboolean new_notification); +void notify_stack_remove_window(NotifyStack* stack, GtkWindow* nw); +GList* notify_stack_get_windows(NotifyStack* stack); +void notify_stack_queue_update_position(NotifyStack* stack); + +#endif /* _NOTIFY_STACK_H_ */ -- cgit v1.2.1