From 914262d420e78766ae11b85403aa2247d5054d46 Mon Sep 17 00:00:00 2001 From: rbuj Date: Sat, 1 Aug 2020 12:52:49 +0200 Subject: geyes: Use common subdirs - src, icons, data --- geyes/Makefile.am | 129 +----- geyes/data/Makefile.am | 46 ++ geyes/data/geyes-applet-menu.xml | 5 + geyes/data/geyes-resources.gresource.xml | 7 + ...ets.GeyesApplet.mate-panel-applet.desktop.in.in | 17 + ...mate.panel.applet.GeyesAppletFactory.service.in | 3 + .../org.mate.panel.applet.geyes.gschema.xml.in | 9 + geyes/data/themes.ui | 171 ++++++++ geyes/geyes-applet-menu.xml | 5 - geyes/geyes-resources.gresource.xml | 7 - geyes/geyes.c | 465 --------------------- geyes/geyes.h | 85 ---- geyes/icons/16x16/apps/mate-eyes-applet.png | Bin 0 -> 651 bytes geyes/icons/22x22/apps/mate-eyes-applet.png | Bin 0 -> 1009 bytes geyes/icons/24x24/apps/mate-eyes-applet.png | Bin 0 -> 1045 bytes geyes/icons/256x256/apps/mate-eyes-applet.png | Bin 0 -> 15560 bytes geyes/icons/32x32/apps/mate-eyes-applet.png | Bin 0 -> 1465 bytes geyes/icons/64x64/apps/mate-eyes-applet.png | Bin 0 -> 2729 bytes geyes/icons/Makefile.am | 30 ++ geyes/icons/scalable/apps/mate-eyes-applet.svg | 410 ++++++++++++++++++ geyes/mate-eyes-applet.16.png | Bin 651 -> 0 bytes geyes/mate-eyes-applet.22.png | Bin 1009 -> 0 bytes geyes/mate-eyes-applet.24.png | Bin 1045 -> 0 bytes geyes/mate-eyes-applet.256.png | Bin 15560 -> 0 bytes geyes/mate-eyes-applet.32.png | Bin 1465 -> 0 bytes geyes/mate-eyes-applet.64.png | Bin 2729 -> 0 bytes geyes/mate-eyes-applet.svg | 410 ------------------ ...ets.GeyesApplet.mate-panel-applet.desktop.in.in | 17 - ...mate.panel.applet.GeyesAppletFactory.service.in | 3 - geyes/org.mate.panel.applet.geyes.gschema.xml.in | 9 - geyes/src/Makefile.am | 36 ++ geyes/src/geyes.c | 465 +++++++++++++++++++++ geyes/src/geyes.h | 85 ++++ geyes/src/themes.c | 351 ++++++++++++++++ geyes/themes.c | 351 ---------------- geyes/themes.ui | 171 -------- 36 files changed, 1638 insertions(+), 1649 deletions(-) create mode 100644 geyes/data/Makefile.am create mode 100644 geyes/data/geyes-applet-menu.xml create mode 100644 geyes/data/geyes-resources.gresource.xml create mode 100644 geyes/data/org.mate.applets.GeyesApplet.mate-panel-applet.desktop.in.in create mode 100644 geyes/data/org.mate.panel.applet.GeyesAppletFactory.service.in create mode 100644 geyes/data/org.mate.panel.applet.geyes.gschema.xml.in create mode 100644 geyes/data/themes.ui delete mode 100644 geyes/geyes-applet-menu.xml delete mode 100644 geyes/geyes-resources.gresource.xml delete mode 100644 geyes/geyes.c delete mode 100644 geyes/geyes.h create mode 100644 geyes/icons/16x16/apps/mate-eyes-applet.png create mode 100644 geyes/icons/22x22/apps/mate-eyes-applet.png create mode 100644 geyes/icons/24x24/apps/mate-eyes-applet.png create mode 100644 geyes/icons/256x256/apps/mate-eyes-applet.png create mode 100644 geyes/icons/32x32/apps/mate-eyes-applet.png create mode 100644 geyes/icons/64x64/apps/mate-eyes-applet.png create mode 100644 geyes/icons/Makefile.am create mode 100644 geyes/icons/scalable/apps/mate-eyes-applet.svg delete mode 100644 geyes/mate-eyes-applet.16.png delete mode 100644 geyes/mate-eyes-applet.22.png delete mode 100644 geyes/mate-eyes-applet.24.png delete mode 100644 geyes/mate-eyes-applet.256.png delete mode 100644 geyes/mate-eyes-applet.32.png delete mode 100644 geyes/mate-eyes-applet.64.png delete mode 100644 geyes/mate-eyes-applet.svg delete mode 100644 geyes/org.mate.applets.GeyesApplet.mate-panel-applet.desktop.in.in delete mode 100644 geyes/org.mate.panel.applet.GeyesAppletFactory.service.in delete mode 100644 geyes/org.mate.panel.applet.geyes.gschema.xml.in create mode 100644 geyes/src/Makefile.am create mode 100644 geyes/src/geyes.c create mode 100644 geyes/src/geyes.h create mode 100644 geyes/src/themes.c delete mode 100644 geyes/themes.c delete mode 100644 geyes/themes.ui (limited to 'geyes') diff --git a/geyes/Makefile.am b/geyes/Makefile.am index 466e7ea7..4bc566b5 100644 --- a/geyes/Makefile.am +++ b/geyes/Makefile.am @@ -1,134 +1,11 @@ NULL = -SUBDIRS = themes docs - -AM_CPPFLAGS = \ - -I. \ - -I$(srcdir) \ - $(MATE_APPLETS4_CFLAGS) \ - -I$(includedir) \ - -DGEYES_THEMES_DIR=\""$(pkgdatadir)/geyes/"\" \ - -DGEYES_RESOURCE_PATH=\""/org/mate/mate-applets/eyes/"\" \ - ${WARN_CFLAGS} - -libexec_PROGRAMS = mate-geyes-applet - -BUILT_SOURCES = geyes-resources.c geyes-resources.h -nodist_mate_geyes_applet_SOURCES = $(BUILT_SOURCES) -mate_geyes_applet_SOURCES = \ - geyes.c \ - geyes.h \ - themes.c \ - $(NULL) - -mate_geyes_applet_LDADD = \ - $(MATE_APPLETS4_LIBS) \ - -lm - -geyes-resources.c: geyes-resources.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/geyes-resources.gresource.xml) - $(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate --c-name eyes $< - -geyes-resources.h: geyes-resources.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/geyes-resources.gresource.xml) - $(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate --c-name eyes $< - -appletdir = $(datadir)/mate-panel/applets -applet_in_files = org.mate.applets.GeyesApplet.mate-panel-applet.desktop.in -applet_DATA = $(applet_in_files:.mate-panel-applet.desktop.in=.mate-panel-applet) - -$(applet_in_files): $(applet_in_files).in Makefile - $(AM_V_GEN)sed \ - -e "s|\@LIBEXECDIR\@|$(libexecdir)|" \ - -e "s|\@VERSION\@|$(PACKAGE_VERSION)|" \ - $< > $@ - -$(applet_DATA): $(applet_in_files) Makefile - $(AM_V_GEN) $(MSGFMT) --desktop --keyword=Name --keyword=Description --template $< -d $(top_srcdir)/po -o $@ - -servicedir = $(datadir)/dbus-1/services -service_in_files = org.mate.panel.applet.GeyesAppletFactory.service.in -service_DATA = $(service_in_files:.service.in=.service) - -org.mate.panel.applet.GeyesAppletFactory.service: $(service_in_files) - $(AM_V_GEN)sed \ - -e "s|\@LIBEXECDIR\@|$(libexecdir)|" \ - $< > $@ - -geyes_gschema_in_files = org.mate.panel.applet.geyes.gschema.xml.in -gsettings_SCHEMAS = $(geyes_gschema_in_files:.xml.in=.xml) -@GSETTINGS_RULES@ +SUBDIRS = data themes docs icons src themesdir = $(pkgdatadir)/geyes -icons = \ - mate-eyes-applet.svg \ - mate-eyes-applet.256.png \ - mate-eyes-applet.64.png \ - mate-eyes-applet.32.png \ - mate-eyes-applet.24.png \ - mate-eyes-applet.22.png \ - mate-eyes-applet.16.png - -CLEANFILES = \ - $(BUILT_SOURCES) \ - $(applet_DATA) \ - $(applet_in_files) \ - $(service_DATA) \ - $(gsettings_SCHEMAS) \ - *.gschema.valid \ +EXTRA_DIST = \ + README.themes \ $(NULL) -EXTRA_DIST = \ - geyes-applet-menu.xml \ - geyes-resources.gresource.xml \ - themes.ui \ - README.themes \ - $(applet_in_files).in \ - $(service_in_files) \ - $(geyes_gschema_in_files) \ - $(icons) \ - $(NULL) - -gtk_update_icon_cache = gtk-update-icon-cache -f -t $(datadir)/icons/hicolor - -uninstall-local: - for icon in $(icons); do \ - SIZE=`echo $$icon | cut -d. -f2`; \ - FILE=`echo $$icon | cut -d. -f1,3`; \ - if [ "$$SIZE" = "svg" ]; then \ - SIZE="scalable"; \ - FILE="$$FILE.svg"; \ - else \ - SIZE="$${SIZE}x$${SIZE}"; \ - fi; \ - rm -f $(DESTDIR)$(iconsdir)/hicolor/$$SIZE/apps/$$FILE; \ - done - @-if test -z "$(DESTDIR)"; then \ - echo "Updating Gtk icon cache."; \ - $(gtk_update_icon_cache); \ - else \ - echo "*** Icon cache not updated. After install, run this:"; \ - echo "*** $(gtk_update_icon_cache)"; \ - fi - -install-data-local: - for icon in $(icons); do \ - SIZE=`echo $$icon | cut -d. -f2`; \ - FILE=`echo $$icon | cut -d. -f1,3`; \ - if [ "$$SIZE" = "svg" ]; then \ - SIZE="scalable"; \ - FILE="$$FILE.svg"; \ - else \ - SIZE="$${SIZE}x$${SIZE}"; \ - fi; \ - mkdir -p $(DESTDIR)$(iconsdir)/hicolor/$$SIZE/apps/; \ - $(INSTALL_DATA) $(srcdir)/$$icon $(DESTDIR)$(iconsdir)/hicolor/$$SIZE/apps/$$FILE; \ - done - @-if test -z "$(DESTDIR)"; then \ - echo "Updating Gtk icon cache."; \ - $(gtk_update_icon_cache); \ - else \ - echo "*** Icon cache not updated. After install, run this:"; \ - echo "*** $(gtk_update_icon_cache)"; \ - fi - -include $(top_srcdir)/git.mk diff --git a/geyes/data/Makefile.am b/geyes/data/Makefile.am new file mode 100644 index 00000000..0342bdaf --- /dev/null +++ b/geyes/data/Makefile.am @@ -0,0 +1,46 @@ +NULL = + +appletdir = $(datadir)/mate-panel/applets +applet_in_files = org.mate.applets.GeyesApplet.mate-panel-applet.desktop.in +applet_DATA = $(applet_in_files:.mate-panel-applet.desktop.in=.mate-panel-applet) + +$(applet_in_files): $(applet_in_files).in Makefile + $(AM_V_GEN)sed \ + -e "s|\@LIBEXECDIR\@|$(libexecdir)|" \ + -e "s|\@VERSION\@|$(PACKAGE_VERSION)|" \ + $< > $@ + +$(applet_DATA): $(applet_in_files) Makefile + $(AM_V_GEN) $(MSGFMT) --desktop --keyword=Name --keyword=Description --template $< -d $(top_srcdir)/po -o $@ + +servicedir = $(datadir)/dbus-1/services +service_in_files = org.mate.panel.applet.GeyesAppletFactory.service.in +service_DATA = $(service_in_files:.service.in=.service) + +org.mate.panel.applet.GeyesAppletFactory.service: $(service_in_files) + $(AM_V_GEN)sed \ + -e "s|\@LIBEXECDIR\@|$(libexecdir)|" \ + $< > $@ + +geyes_gschema_in_files = org.mate.panel.applet.geyes.gschema.xml.in +gsettings_SCHEMAS = $(geyes_gschema_in_files:.xml.in=.xml) +@GSETTINGS_RULES@ + +CLEANFILES = \ + $(applet_DATA) \ + $(applet_in_files) \ + $(service_DATA) \ + $(gsettings_SCHEMAS) \ + *.gschema.valid \ + $(NULL) + +EXTRA_DIST = \ + geyes-applet-menu.xml \ + geyes-resources.gresource.xml \ + themes.ui \ + $(applet_in_files).in \ + $(service_in_files) \ + $(geyes_gschema_in_files) \ + $(NULL) + +-include $(top_srcdir)/git.mk diff --git a/geyes/data/geyes-applet-menu.xml b/geyes/data/geyes-applet-menu.xml new file mode 100644 index 00000000..860052ae --- /dev/null +++ b/geyes/data/geyes-applet-menu.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/geyes/data/geyes-resources.gresource.xml b/geyes/data/geyes-resources.gresource.xml new file mode 100644 index 00000000..4a7dc547 --- /dev/null +++ b/geyes/data/geyes-resources.gresource.xml @@ -0,0 +1,7 @@ + + + + geyes-applet-menu.xml + themes.ui + + diff --git a/geyes/data/org.mate.applets.GeyesApplet.mate-panel-applet.desktop.in.in b/geyes/data/org.mate.applets.GeyesApplet.mate-panel-applet.desktop.in.in new file mode 100644 index 00000000..eaadb5f3 --- /dev/null +++ b/geyes/data/org.mate.applets.GeyesApplet.mate-panel-applet.desktop.in.in @@ -0,0 +1,17 @@ +[Applet Factory] +Id=GeyesAppletFactory +Location=@LIBEXECDIR@/mate-geyes-applet +Name=Eyes Applet Factory +Description=Eyes Applet Factory + +[GeyesApplet] +Name=Eyes +Description=A set of eyeballs for your panel +# Translators: Do NOT translate or transliterate this text (this is an icon file name)! +Icon=mate-eyes-applet +MateComponentId=OAFIID:MATE_GeyesApplet +X-MATE-Bugzilla-Bugzilla=MATE +X-MATE-Bugzilla-Product=mate-applets +X-MATE-Bugzilla-Component=geyes +X-MATE-Bugzilla-Version=@VERSION@ +X-MATE-Bugzilla-OtherBinaries=geyes_applet2 diff --git a/geyes/data/org.mate.panel.applet.GeyesAppletFactory.service.in b/geyes/data/org.mate.panel.applet.GeyesAppletFactory.service.in new file mode 100644 index 00000000..2f490e7b --- /dev/null +++ b/geyes/data/org.mate.panel.applet.GeyesAppletFactory.service.in @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=org.mate.panel.applet.GeyesAppletFactory +Exec=@LIBEXECDIR@/mate-geyes-applet diff --git a/geyes/data/org.mate.panel.applet.geyes.gschema.xml.in b/geyes/data/org.mate.panel.applet.geyes.gschema.xml.in new file mode 100644 index 00000000..aad28f71 --- /dev/null +++ b/geyes/data/org.mate.panel.applet.geyes.gschema.xml.in @@ -0,0 +1,9 @@ + + + + '' + Directory in which the theme is located + Directory in which the theme is located + + + diff --git a/geyes/data/themes.ui b/geyes/data/themes.ui new file mode 100644 index 00000000..70409f3b --- /dev/null +++ b/geyes/data/themes.ui @@ -0,0 +1,171 @@ + + + + + + True + False + help-browser + + + True + False + window-close + + + False + 12 + Eyes Preferences + 300 + 200 + mate-eyes-applet + dialog + + + + False + vertical + 2 + + + False + end + + + _Help + True + True + True + image1 + True + True + + + True + True + 0 + + + + + _Close + True + True + True + True + True + image2 + True + True + + + True + True + 1 + + + + + False + False + 0 + + + + + True + False + True + 0 + none + + + True + False + 12 + + + True + False + 6 + 6 + True + vertical + 6 + + + True + False + start + _Select a theme: + True + themes_treeview + + + False + True + 0 + + + + + True + True + True + True + never + in + + + True + True + True + True + False + False + + + + + + + + + + False + True + 1 + + + + + + + + + True + False + Themes + + + + + + + + False + True + 1 + + + + + + button1 + button2 + + + + + + diff --git a/geyes/geyes-applet-menu.xml b/geyes/geyes-applet-menu.xml deleted file mode 100644 index 860052ae..00000000 --- a/geyes/geyes-applet-menu.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/geyes/geyes-resources.gresource.xml b/geyes/geyes-resources.gresource.xml deleted file mode 100644 index 4a7dc547..00000000 --- a/geyes/geyes-resources.gresource.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - geyes-applet-menu.xml - themes.ui - - diff --git a/geyes/geyes.c b/geyes/geyes.c deleted file mode 100644 index 4adf7e87..00000000 --- a/geyes/geyes.c +++ /dev/null @@ -1,465 +0,0 @@ -/* -*- Mode: C; c-basic-offset: 4 -*- - * geyes.c - A cheap xeyes ripoff. - * Copyright (C) 1999 Dave Camp - * - * 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 of the License, 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include -#include -#include -#include "geyes.h" - -#define UPDATE_TIMEOUT 100 - -static gfloat -gtk_align_to_gfloat (GtkAlign align) -{ - switch (align) { - case GTK_ALIGN_START: - return 0.0; - case GTK_ALIGN_END: - return 1.0; - case GTK_ALIGN_CENTER: - case GTK_ALIGN_FILL: - return 0.5; - default: - return 0.0; - } -} - -/* TODO - Optimize this a bit */ -static void -calculate_pupil_xy (EyesApplet *eyes_applet, - gint x, gint y, - gint *pupil_x, gint *pupil_y, GtkWidget* widget) -{ - GtkAllocation allocation; - double sina; - double cosa; - double h; - double temp; - double nx, ny; - - gfloat xalign, yalign; - gint width, height; - - gtk_widget_get_allocation (GTK_WIDGET(widget), &allocation); - width = allocation.width; - height = allocation.height; - xalign = gtk_align_to_gfloat (gtk_widget_get_halign (widget)); - yalign = gtk_align_to_gfloat (gtk_widget_get_valign (widget)); - - nx = x - MAX(width - eyes_applet->eye_width, 0) * xalign - eyes_applet->eye_width / 2; - ny = y - MAX(height- eyes_applet->eye_height, 0) * yalign - eyes_applet->eye_height / 2; - - h = hypot (nx, ny); - if (h < 0.5 || fabs (h) - < (fabs (hypot (eyes_applet->eye_height / 2, eyes_applet->eye_width / 2)) - eyes_applet->wall_thickness - eyes_applet->pupil_height)) { - *pupil_x = nx + eyes_applet->eye_width / 2; - *pupil_y = ny + eyes_applet->eye_height / 2; - return; - } - - sina = nx / h; - cosa = ny / h; - - temp = hypot ((eyes_applet->eye_width / 2) * sina, (eyes_applet->eye_height / 2) * cosa); - temp -= hypot ((eyes_applet->pupil_width / 2) * sina, (eyes_applet->pupil_height / 2) * cosa); - temp -= hypot ((eyes_applet->wall_thickness / 2) * sina, (eyes_applet->wall_thickness / 2) * cosa); - - *pupil_x = temp * sina + (eyes_applet->eye_width / 2); - *pupil_y = temp * cosa + (eyes_applet->eye_height / 2); -} - -static void -draw_eye (EyesApplet *eyes_applet, - gint eye_num, - gint pupil_x, - gint pupil_y) -{ - GdkPixbuf *pixbuf; - GdkRectangle rect, r1, r2; - - pixbuf = gdk_pixbuf_copy (eyes_applet->eye_image); - r1.x = pupil_x - eyes_applet->pupil_width / 2; - r1.y = pupil_y - eyes_applet->pupil_height / 2; - r1.width = eyes_applet->pupil_width; - r1.height = eyes_applet->pupil_height; - r2.x = 0; - r2.y = 0; - r2.width = eyes_applet->eye_width; - r2.height = eyes_applet->eye_height; - gdk_rectangle_intersect (&r1, &r2, &rect); - gdk_pixbuf_composite (eyes_applet->pupil_image, pixbuf, - rect.x, - rect.y, - rect.width, - rect.height, - pupil_x - eyes_applet->pupil_width / 2, - pupil_y - eyes_applet->pupil_height / 2, 1.0, 1.0, - GDK_INTERP_BILINEAR, - 255); - gtk_image_set_from_pixbuf (GTK_IMAGE (eyes_applet->eyes[eye_num]), - pixbuf); - g_object_unref (pixbuf); - -} - -static gint -timer_cb (EyesApplet *eyes_applet) -{ - GdkDisplay *display; - GdkSeat *seat; - gint x, y; - gint pupil_x, pupil_y; - gint i; - - display = gtk_widget_get_display (GTK_WIDGET (eyes_applet->applet)); - seat = gdk_display_get_default_seat (display); - - for (i = 0; i < eyes_applet->num_eyes; i++) { - if (gtk_widget_get_realized (eyes_applet->eyes[i])) { - gdk_window_get_device_position (gtk_widget_get_window (eyes_applet->eyes[i]), - gdk_seat_get_pointer (seat), - &x, &y, NULL); - - if ((x != eyes_applet->pointer_last_x[i]) || (y != eyes_applet->pointer_last_y[i])) { - - calculate_pupil_xy (eyes_applet, x, y, &pupil_x, &pupil_y, eyes_applet->eyes[i]); - draw_eye (eyes_applet, i, pupil_x, pupil_y); - - eyes_applet->pointer_last_x[i] = x; - eyes_applet->pointer_last_y[i] = y; - } - } - } - return TRUE; -} - -static void -about_cb (GtkAction *action, - EyesApplet *eyes_applet) -{ - static const gchar *authors [] = { - "Dave Camp ", - NULL - }; - - const gchar *documenters[] = { - "Arjan Scherpenisse ", - "Telsa Gwynne ", - N_("Sun GNOME Documentation Team "), - N_("MATE Documentation Team"), - NULL - }; - -#ifdef ENABLE_NLS - const char **p; - for (p = documenters; *p; ++p) - *p = _(*p); -#endif - - gtk_show_about_dialog (NULL, - "title", _("About Eyes"), - "version", VERSION, - "comments", _("A goofy set of eyes for the MATE " - "panel. They follow your mouse."), - "copyright", _("Copyright \xC2\xA9 1999 Dave Camp\n" - "Copyright \xc2\xa9 2012-2020 MATE developers"), - "authors", authors, - "documenters", documenters, - "translator-credits", _("translator-credits"), - "logo-icon-name", "mate-eyes-applet", - NULL); -} - -static int -properties_load (EyesApplet *eyes_applet) -{ - gchar *theme_path = NULL; - - theme_path = g_settings_get_string (eyes_applet->settings, "theme-path"); - - if (theme_path == NULL) - theme_path = g_strdup (GEYES_THEMES_DIR "Default-tiny"); - - if (load_theme (eyes_applet, theme_path) == FALSE) { - g_free (theme_path); - - return FALSE; - } - - g_free (theme_path); - - return TRUE; -} - -void -setup_eyes (EyesApplet *eyes_applet) -{ - int i; - - eyes_applet->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_pack_start (GTK_BOX (eyes_applet->vbox), eyes_applet->hbox, TRUE, TRUE, 0); - - eyes_applet->eyes = g_new0 (GtkWidget *, eyes_applet->num_eyes); - eyes_applet->pointer_last_x = g_new0 (gint, eyes_applet->num_eyes); - eyes_applet->pointer_last_y = g_new0 (gint, eyes_applet->num_eyes); - - for (i = 0; i < eyes_applet->num_eyes; i++) { - eyes_applet->eyes[i] = gtk_image_new (); - if (eyes_applet->eyes[i] == NULL) - g_error ("Error creating geyes\n"); - - gtk_widget_set_size_request (GTK_WIDGET (eyes_applet->eyes[i]), - eyes_applet->eye_width, - eyes_applet->eye_height); - - gtk_widget_show (eyes_applet->eyes[i]); - - gtk_box_pack_start (GTK_BOX (eyes_applet->hbox), - eyes_applet->eyes [i], - TRUE, - TRUE, - 0); - - if ((eyes_applet->num_eyes != 1) && (i == 0)) { - gtk_widget_set_halign (eyes_applet->eyes[i], GTK_ALIGN_END); - gtk_widget_set_valign (eyes_applet->eyes[i], GTK_ALIGN_CENTER); - } - else if ((eyes_applet->num_eyes != 1) && (i == eyes_applet->num_eyes - 1)) { - gtk_widget_set_halign (eyes_applet->eyes[i], GTK_ALIGN_START); - gtk_widget_set_valign (eyes_applet->eyes[i], GTK_ALIGN_CENTER); - } - else { - gtk_widget_set_halign (eyes_applet->eyes[i], GTK_ALIGN_CENTER); - gtk_widget_set_valign (eyes_applet->eyes[i], GTK_ALIGN_CENTER); - } - - gtk_widget_realize (eyes_applet->eyes[i]); - - eyes_applet->pointer_last_x[i] = G_MAXINT; - eyes_applet->pointer_last_y[i] = G_MAXINT; - - draw_eye (eyes_applet, i, - eyes_applet->eye_width / 2, - eyes_applet->eye_height / 2); - - } - gtk_widget_show (eyes_applet->hbox); -} - -void -destroy_eyes (EyesApplet *eyes_applet) -{ - gtk_widget_destroy (eyes_applet->hbox); - eyes_applet->hbox = NULL; - - g_free (eyes_applet->eyes); - g_free (eyes_applet->pointer_last_x); - g_free (eyes_applet->pointer_last_y); -} - -static EyesApplet * -create_eyes (MatePanelApplet *applet) -{ - EyesApplet *eyes_applet = g_new0 (EyesApplet, 1); - - eyes_applet->applet = applet; - eyes_applet->vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - eyes_applet->settings = - mate_panel_applet_settings_new (applet, "org.mate.panel.applet.geyes"); - - gtk_container_add (GTK_CONTAINER (applet), eyes_applet->vbox); - - return eyes_applet; -} - -static void -dispose_cb (GObject *object, EyesApplet *eyes_applet) -{ - g_return_if_fail (eyes_applet); - - g_source_remove (eyes_applet->timeout_id); - if (eyes_applet->hbox) - destroy_eyes (eyes_applet); - eyes_applet->timeout_id = 0; - if (eyes_applet->eye_image) - g_object_unref (eyes_applet->eye_image); - eyes_applet->eye_image = NULL; - if (eyes_applet->pupil_image) - g_object_unref (eyes_applet->pupil_image); - eyes_applet->pupil_image = NULL; - if (eyes_applet->theme_dir) - g_free (eyes_applet->theme_dir); - eyes_applet->theme_dir = NULL; - if (eyes_applet->theme_name) - g_free (eyes_applet->theme_name); - eyes_applet->theme_name = NULL; - if (eyes_applet->eye_filename) - g_free (eyes_applet->eye_filename); - eyes_applet->eye_filename = NULL; - if (eyes_applet->pupil_filename) - g_free (eyes_applet->pupil_filename); - eyes_applet->pupil_filename = NULL; - - if (eyes_applet->prop_box.pbox) - gtk_widget_destroy (eyes_applet->prop_box.pbox); - - if (eyes_applet->settings) - g_object_unref (eyes_applet->settings); - eyes_applet->settings = NULL; - - g_free (eyes_applet); -} - -static void -help_cb (GtkAction *action, - EyesApplet *eyes_applet) -{ - GError *error = NULL; - - gtk_show_uri_on_window (NULL, - "help:mate-geyes", - gtk_get_current_event_time (), - &error); - - if (error) { - GtkWidget *dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - _("There was an error displaying help: %s"), error->message); - g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (gtk_widget_destroy), NULL); - gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); - gtk_window_set_screen (GTK_WINDOW (dialog), gtk_widget_get_screen (GTK_WIDGET (eyes_applet->applet))); - gtk_widget_show (dialog); - g_error_free (error); - error = NULL; - } -} - - -static const GtkActionEntry geyes_applet_menu_actions [] = { - { "Props", "document-properties", N_("_Preferences"), - NULL, NULL, - G_CALLBACK (properties_cb) }, - { "Help", "help-browser", N_("_Help"), - NULL, NULL, - G_CALLBACK (help_cb) }, - { "About", "help-about", N_("_About"), - NULL, NULL, - G_CALLBACK (about_cb) } -}; - -static void -set_atk_name_description (GtkWidget *widget, const gchar *name, - const gchar *description) -{ - AtkObject *aobj; - - aobj = gtk_widget_get_accessible (widget); - /* Check if gail is loaded */ - if (GTK_IS_ACCESSIBLE (aobj) == FALSE) - return; - - atk_object_set_name (aobj, name); - atk_object_set_description (aobj, description); -} - -static gboolean -geyes_applet_fill (MatePanelApplet *applet) -{ - EyesApplet *eyes_applet; - GtkActionGroup *action_group; - - g_set_application_name (_("Eyes")); - - gtk_window_set_default_icon_name ("mate-eyes-applet"); - mate_panel_applet_set_flags (applet, MATE_PANEL_APPLET_EXPAND_MINOR); - mate_panel_applet_set_background_widget (applet, GTK_WIDGET (applet)); - - eyes_applet = create_eyes (applet); - - eyes_applet->timeout_id = g_timeout_add ( - UPDATE_TIMEOUT, (GSourceFunc) timer_cb, eyes_applet); - - action_group = gtk_action_group_new ("Geyes Applet Actions"); - gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE); - - gtk_action_group_add_actions (action_group, - geyes_applet_menu_actions, - G_N_ELEMENTS (geyes_applet_menu_actions), - eyes_applet); - - mate_panel_applet_setup_menu_from_resource (eyes_applet->applet, - GEYES_RESOURCE_PATH "geyes-applet-menu.xml", - action_group); - - if (mate_panel_applet_get_locked_down (eyes_applet->applet)) { - GtkAction *action; - - action = gtk_action_group_get_action (action_group, "Props"); - gtk_action_set_visible (action, FALSE); - } - g_object_unref (action_group); - - gtk_widget_set_tooltip_text (GTK_WIDGET (eyes_applet->applet), _("Eyes")); - - set_atk_name_description (GTK_WIDGET (eyes_applet->applet), _("Eyes"), - _("The eyes look in the direction of the mouse pointer")); - - g_signal_connect (eyes_applet->vbox, - "dispose", - G_CALLBACK (dispose_cb), - eyes_applet); - - gtk_widget_show_all (GTK_WIDGET (eyes_applet->applet)); - - /* setup here and not in create eyes so the destroy signal is set so - * that when there is an error within loading the theme - * we can emit this signal */ - if (properties_load (eyes_applet) == FALSE) - return FALSE; - - setup_eyes (eyes_applet); - - return TRUE; -} - -static gboolean -geyes_applet_factory (MatePanelApplet *applet, - const gchar *iid, - gpointer data) -{ - gboolean retval = FALSE; - - theme_dirs_create (); - - if (!strcmp (iid, "GeyesApplet")) - retval = geyes_applet_fill (applet); - - if (retval == FALSE) { - exit (-1); - } - - return retval; -} - -MATE_PANEL_APPLET_OUT_PROCESS_FACTORY ("GeyesAppletFactory", - PANEL_TYPE_APPLET, - "geyes", - geyes_applet_factory, - NULL) diff --git a/geyes/geyes.h b/geyes/geyes.h deleted file mode 100644 index 3fb24457..00000000 --- a/geyes/geyes.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) 1999 Dave Camp - * - * 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 of the License, 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef __GEYES_H__ -#define __GEYES_H__ - -#include -#include -#include -#include -#include -#include - -#define MAX_EYES 1000 -typedef struct -{ - GtkWidget *pbox; - - gint selected_row; -} EyesPropertyBox; - -typedef struct -{ - /* Applet */ - MatePanelApplet *applet; - GtkWidget *vbox; - GtkWidget *hbox; - GtkWidget **eyes; - guint timeout_id; - gint *pointer_last_x; - gint *pointer_last_y; - - /* Theme */ - GdkPixbuf *eye_image; - GdkPixbuf *pupil_image; - gchar *theme_dir; - gchar *theme_name; - gchar *eye_filename; - gchar *pupil_filename; - gint num_eyes; - gint eye_height; - gint eye_width; - gint pupil_height; - gint pupil_width; - gint wall_thickness; - - /* Properties */ - EyesPropertyBox prop_box; - - /* Settings */ - GSettings *settings; -} EyesApplet; - -/* eyes.c */ -void setup_eyes (EyesApplet *eyes_applet); - -void destroy_eyes (EyesApplet *eyes_applet); - - -/* theme.c */ -void theme_dirs_create (void); - -int load_theme (EyesApplet *eyes_applet, - const gchar *theme_dir); - -void properties_cb (GtkAction *action, - EyesApplet *eyes_applet); - -#endif diff --git a/geyes/icons/16x16/apps/mate-eyes-applet.png b/geyes/icons/16x16/apps/mate-eyes-applet.png new file mode 100644 index 00000000..dbf835b1 Binary files /dev/null and b/geyes/icons/16x16/apps/mate-eyes-applet.png differ diff --git a/geyes/icons/22x22/apps/mate-eyes-applet.png b/geyes/icons/22x22/apps/mate-eyes-applet.png new file mode 100644 index 00000000..dac46187 Binary files /dev/null and b/geyes/icons/22x22/apps/mate-eyes-applet.png differ diff --git a/geyes/icons/24x24/apps/mate-eyes-applet.png b/geyes/icons/24x24/apps/mate-eyes-applet.png new file mode 100644 index 00000000..49531a98 Binary files /dev/null and b/geyes/icons/24x24/apps/mate-eyes-applet.png differ diff --git a/geyes/icons/256x256/apps/mate-eyes-applet.png b/geyes/icons/256x256/apps/mate-eyes-applet.png new file mode 100644 index 00000000..c0509438 Binary files /dev/null and b/geyes/icons/256x256/apps/mate-eyes-applet.png differ diff --git a/geyes/icons/32x32/apps/mate-eyes-applet.png b/geyes/icons/32x32/apps/mate-eyes-applet.png new file mode 100644 index 00000000..08e531c9 Binary files /dev/null and b/geyes/icons/32x32/apps/mate-eyes-applet.png differ diff --git a/geyes/icons/64x64/apps/mate-eyes-applet.png b/geyes/icons/64x64/apps/mate-eyes-applet.png new file mode 100644 index 00000000..ae7a2226 Binary files /dev/null and b/geyes/icons/64x64/apps/mate-eyes-applet.png differ diff --git a/geyes/icons/Makefile.am b/geyes/icons/Makefile.am new file mode 100644 index 00000000..92fa7f75 --- /dev/null +++ b/geyes/icons/Makefile.am @@ -0,0 +1,30 @@ +iconsdir = $(datadir)/icons/hicolor + +png_icons = \ + 16x16/apps/mate-eyes-applet.png \ + 22x22/apps/mate-eyes-applet.png \ + 24x24/apps/mate-eyes-applet.png \ + 32x32/apps/mate-eyes-applet.png \ + 64x64/apps/mate-eyes-applet.png \ + 256x256/apps/mate-eyes-applet.png \ + $(NULL) + +nobase_dist_icons_DATA = \ + $(png_icons) \ + scalable/apps/mate-eyes-applet.svg \ + $(NULL) + +gtk_update_icon_cache = gtk-update-icon-cache -f -t $(iconsdir) + +install-data-hook: update-icon-cache +uninstall-hook: update-icon-cache +update-icon-cache: + @-if test -z "$(DESTDIR)"; then \ + echo "Updating Gtk icon cache."; \ + $(gtk_update_icon_cache); \ + else \ + echo "*** Icon cache not updated. After install, run this:"; \ + echo "*** $(gtk_update_icon_cache)"; \ + fi + +-include $(top_srcdir)/git.mk diff --git a/geyes/icons/scalable/apps/mate-eyes-applet.svg b/geyes/icons/scalable/apps/mate-eyes-applet.svg new file mode 100644 index 00000000..1128d45e --- /dev/null +++ b/geyes/icons/scalable/apps/mate-eyes-applet.svg @@ -0,0 +1,410 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + Lapo Calamandrei + + + Mate Eyes + + + eyes + toy + + + + + + Jakub Steiner + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/geyes/mate-eyes-applet.16.png b/geyes/mate-eyes-applet.16.png deleted file mode 100644 index dbf835b1..00000000 Binary files a/geyes/mate-eyes-applet.16.png and /dev/null differ diff --git a/geyes/mate-eyes-applet.22.png b/geyes/mate-eyes-applet.22.png deleted file mode 100644 index dac46187..00000000 Binary files a/geyes/mate-eyes-applet.22.png and /dev/null differ diff --git a/geyes/mate-eyes-applet.24.png b/geyes/mate-eyes-applet.24.png deleted file mode 100644 index 49531a98..00000000 Binary files a/geyes/mate-eyes-applet.24.png and /dev/null differ diff --git a/geyes/mate-eyes-applet.256.png b/geyes/mate-eyes-applet.256.png deleted file mode 100644 index c0509438..00000000 Binary files a/geyes/mate-eyes-applet.256.png and /dev/null differ diff --git a/geyes/mate-eyes-applet.32.png b/geyes/mate-eyes-applet.32.png deleted file mode 100644 index 08e531c9..00000000 Binary files a/geyes/mate-eyes-applet.32.png and /dev/null differ diff --git a/geyes/mate-eyes-applet.64.png b/geyes/mate-eyes-applet.64.png deleted file mode 100644 index ae7a2226..00000000 Binary files a/geyes/mate-eyes-applet.64.png and /dev/null differ diff --git a/geyes/mate-eyes-applet.svg b/geyes/mate-eyes-applet.svg deleted file mode 100644 index 1128d45e..00000000 --- a/geyes/mate-eyes-applet.svg +++ /dev/null @@ -1,410 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - Lapo Calamandrei - - - Mate Eyes - - - eyes - toy - - - - - - Jakub Steiner - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/geyes/org.mate.applets.GeyesApplet.mate-panel-applet.desktop.in.in b/geyes/org.mate.applets.GeyesApplet.mate-panel-applet.desktop.in.in deleted file mode 100644 index eaadb5f3..00000000 --- a/geyes/org.mate.applets.GeyesApplet.mate-panel-applet.desktop.in.in +++ /dev/null @@ -1,17 +0,0 @@ -[Applet Factory] -Id=GeyesAppletFactory -Location=@LIBEXECDIR@/mate-geyes-applet -Name=Eyes Applet Factory -Description=Eyes Applet Factory - -[GeyesApplet] -Name=Eyes -Description=A set of eyeballs for your panel -# Translators: Do NOT translate or transliterate this text (this is an icon file name)! -Icon=mate-eyes-applet -MateComponentId=OAFIID:MATE_GeyesApplet -X-MATE-Bugzilla-Bugzilla=MATE -X-MATE-Bugzilla-Product=mate-applets -X-MATE-Bugzilla-Component=geyes -X-MATE-Bugzilla-Version=@VERSION@ -X-MATE-Bugzilla-OtherBinaries=geyes_applet2 diff --git a/geyes/org.mate.panel.applet.GeyesAppletFactory.service.in b/geyes/org.mate.panel.applet.GeyesAppletFactory.service.in deleted file mode 100644 index 2f490e7b..00000000 --- a/geyes/org.mate.panel.applet.GeyesAppletFactory.service.in +++ /dev/null @@ -1,3 +0,0 @@ -[D-BUS Service] -Name=org.mate.panel.applet.GeyesAppletFactory -Exec=@LIBEXECDIR@/mate-geyes-applet diff --git a/geyes/org.mate.panel.applet.geyes.gschema.xml.in b/geyes/org.mate.panel.applet.geyes.gschema.xml.in deleted file mode 100644 index aad28f71..00000000 --- a/geyes/org.mate.panel.applet.geyes.gschema.xml.in +++ /dev/null @@ -1,9 +0,0 @@ - - - - '' - Directory in which the theme is located - Directory in which the theme is located - - - diff --git a/geyes/src/Makefile.am b/geyes/src/Makefile.am new file mode 100644 index 00000000..22856564 --- /dev/null +++ b/geyes/src/Makefile.am @@ -0,0 +1,36 @@ +NULL = + +AM_CPPFLAGS = \ + -I. \ + -I$(srcdir) \ + $(MATE_APPLETS4_CFLAGS) \ + -I$(includedir) \ + -DGEYES_THEMES_DIR=\""$(pkgdatadir)/geyes/"\" \ + -DGEYES_RESOURCE_PATH=\""/org/mate/mate-applets/eyes/"\" \ + ${WARN_CFLAGS} + +libexec_PROGRAMS = mate-geyes-applet + +BUILT_SOURCES = geyes-resources.c geyes-resources.h +nodist_mate_geyes_applet_SOURCES = $(BUILT_SOURCES) +mate_geyes_applet_SOURCES = \ + geyes.c \ + geyes.h \ + themes.c \ + $(NULL) + +mate_geyes_applet_LDADD = \ + $(MATE_APPLETS4_LIBS) \ + -lm + +geyes-resources.c: $(srcdir)/../data/geyes-resources.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir)/../data --generate-dependencies $(srcdir)/../data/geyes-resources.gresource.xml) + $(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir)/../data --generate --c-name eyes $< + +geyes-resources.h: $(srcdir)/../data/geyes-resources.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir)/../data --generate-dependencies $(srcdir)/../data/geyes-resources.gresource.xml) + $(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir)/../data --generate --c-name eyes $< + +CLEANFILES = \ + $(BUILT_SOURCES) \ + $(NULL) + +-include $(top_srcdir)/git.mk diff --git a/geyes/src/geyes.c b/geyes/src/geyes.c new file mode 100644 index 00000000..4adf7e87 --- /dev/null +++ b/geyes/src/geyes.c @@ -0,0 +1,465 @@ +/* -*- Mode: C; c-basic-offset: 4 -*- + * geyes.c - A cheap xeyes ripoff. + * Copyright (C) 1999 Dave Camp + * + * 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 of the License, 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include +#include +#include "geyes.h" + +#define UPDATE_TIMEOUT 100 + +static gfloat +gtk_align_to_gfloat (GtkAlign align) +{ + switch (align) { + case GTK_ALIGN_START: + return 0.0; + case GTK_ALIGN_END: + return 1.0; + case GTK_ALIGN_CENTER: + case GTK_ALIGN_FILL: + return 0.5; + default: + return 0.0; + } +} + +/* TODO - Optimize this a bit */ +static void +calculate_pupil_xy (EyesApplet *eyes_applet, + gint x, gint y, + gint *pupil_x, gint *pupil_y, GtkWidget* widget) +{ + GtkAllocation allocation; + double sina; + double cosa; + double h; + double temp; + double nx, ny; + + gfloat xalign, yalign; + gint width, height; + + gtk_widget_get_allocation (GTK_WIDGET(widget), &allocation); + width = allocation.width; + height = allocation.height; + xalign = gtk_align_to_gfloat (gtk_widget_get_halign (widget)); + yalign = gtk_align_to_gfloat (gtk_widget_get_valign (widget)); + + nx = x - MAX(width - eyes_applet->eye_width, 0) * xalign - eyes_applet->eye_width / 2; + ny = y - MAX(height- eyes_applet->eye_height, 0) * yalign - eyes_applet->eye_height / 2; + + h = hypot (nx, ny); + if (h < 0.5 || fabs (h) + < (fabs (hypot (eyes_applet->eye_height / 2, eyes_applet->eye_width / 2)) - eyes_applet->wall_thickness - eyes_applet->pupil_height)) { + *pupil_x = nx + eyes_applet->eye_width / 2; + *pupil_y = ny + eyes_applet->eye_height / 2; + return; + } + + sina = nx / h; + cosa = ny / h; + + temp = hypot ((eyes_applet->eye_width / 2) * sina, (eyes_applet->eye_height / 2) * cosa); + temp -= hypot ((eyes_applet->pupil_width / 2) * sina, (eyes_applet->pupil_height / 2) * cosa); + temp -= hypot ((eyes_applet->wall_thickness / 2) * sina, (eyes_applet->wall_thickness / 2) * cosa); + + *pupil_x = temp * sina + (eyes_applet->eye_width / 2); + *pupil_y = temp * cosa + (eyes_applet->eye_height / 2); +} + +static void +draw_eye (EyesApplet *eyes_applet, + gint eye_num, + gint pupil_x, + gint pupil_y) +{ + GdkPixbuf *pixbuf; + GdkRectangle rect, r1, r2; + + pixbuf = gdk_pixbuf_copy (eyes_applet->eye_image); + r1.x = pupil_x - eyes_applet->pupil_width / 2; + r1.y = pupil_y - eyes_applet->pupil_height / 2; + r1.width = eyes_applet->pupil_width; + r1.height = eyes_applet->pupil_height; + r2.x = 0; + r2.y = 0; + r2.width = eyes_applet->eye_width; + r2.height = eyes_applet->eye_height; + gdk_rectangle_intersect (&r1, &r2, &rect); + gdk_pixbuf_composite (eyes_applet->pupil_image, pixbuf, + rect.x, + rect.y, + rect.width, + rect.height, + pupil_x - eyes_applet->pupil_width / 2, + pupil_y - eyes_applet->pupil_height / 2, 1.0, 1.0, + GDK_INTERP_BILINEAR, + 255); + gtk_image_set_from_pixbuf (GTK_IMAGE (eyes_applet->eyes[eye_num]), + pixbuf); + g_object_unref (pixbuf); + +} + +static gint +timer_cb (EyesApplet *eyes_applet) +{ + GdkDisplay *display; + GdkSeat *seat; + gint x, y; + gint pupil_x, pupil_y; + gint i; + + display = gtk_widget_get_display (GTK_WIDGET (eyes_applet->applet)); + seat = gdk_display_get_default_seat (display); + + for (i = 0; i < eyes_applet->num_eyes; i++) { + if (gtk_widget_get_realized (eyes_applet->eyes[i])) { + gdk_window_get_device_position (gtk_widget_get_window (eyes_applet->eyes[i]), + gdk_seat_get_pointer (seat), + &x, &y, NULL); + + if ((x != eyes_applet->pointer_last_x[i]) || (y != eyes_applet->pointer_last_y[i])) { + + calculate_pupil_xy (eyes_applet, x, y, &pupil_x, &pupil_y, eyes_applet->eyes[i]); + draw_eye (eyes_applet, i, pupil_x, pupil_y); + + eyes_applet->pointer_last_x[i] = x; + eyes_applet->pointer_last_y[i] = y; + } + } + } + return TRUE; +} + +static void +about_cb (GtkAction *action, + EyesApplet *eyes_applet) +{ + static const gchar *authors [] = { + "Dave Camp ", + NULL + }; + + const gchar *documenters[] = { + "Arjan Scherpenisse ", + "Telsa Gwynne ", + N_("Sun GNOME Documentation Team "), + N_("MATE Documentation Team"), + NULL + }; + +#ifdef ENABLE_NLS + const char **p; + for (p = documenters; *p; ++p) + *p = _(*p); +#endif + + gtk_show_about_dialog (NULL, + "title", _("About Eyes"), + "version", VERSION, + "comments", _("A goofy set of eyes for the MATE " + "panel. They follow your mouse."), + "copyright", _("Copyright \xC2\xA9 1999 Dave Camp\n" + "Copyright \xc2\xa9 2012-2020 MATE developers"), + "authors", authors, + "documenters", documenters, + "translator-credits", _("translator-credits"), + "logo-icon-name", "mate-eyes-applet", + NULL); +} + +static int +properties_load (EyesApplet *eyes_applet) +{ + gchar *theme_path = NULL; + + theme_path = g_settings_get_string (eyes_applet->settings, "theme-path"); + + if (theme_path == NULL) + theme_path = g_strdup (GEYES_THEMES_DIR "Default-tiny"); + + if (load_theme (eyes_applet, theme_path) == FALSE) { + g_free (theme_path); + + return FALSE; + } + + g_free (theme_path); + + return TRUE; +} + +void +setup_eyes (EyesApplet *eyes_applet) +{ + int i; + + eyes_applet->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_box_pack_start (GTK_BOX (eyes_applet->vbox), eyes_applet->hbox, TRUE, TRUE, 0); + + eyes_applet->eyes = g_new0 (GtkWidget *, eyes_applet->num_eyes); + eyes_applet->pointer_last_x = g_new0 (gint, eyes_applet->num_eyes); + eyes_applet->pointer_last_y = g_new0 (gint, eyes_applet->num_eyes); + + for (i = 0; i < eyes_applet->num_eyes; i++) { + eyes_applet->eyes[i] = gtk_image_new (); + if (eyes_applet->eyes[i] == NULL) + g_error ("Error creating geyes\n"); + + gtk_widget_set_size_request (GTK_WIDGET (eyes_applet->eyes[i]), + eyes_applet->eye_width, + eyes_applet->eye_height); + + gtk_widget_show (eyes_applet->eyes[i]); + + gtk_box_pack_start (GTK_BOX (eyes_applet->hbox), + eyes_applet->eyes [i], + TRUE, + TRUE, + 0); + + if ((eyes_applet->num_eyes != 1) && (i == 0)) { + gtk_widget_set_halign (eyes_applet->eyes[i], GTK_ALIGN_END); + gtk_widget_set_valign (eyes_applet->eyes[i], GTK_ALIGN_CENTER); + } + else if ((eyes_applet->num_eyes != 1) && (i == eyes_applet->num_eyes - 1)) { + gtk_widget_set_halign (eyes_applet->eyes[i], GTK_ALIGN_START); + gtk_widget_set_valign (eyes_applet->eyes[i], GTK_ALIGN_CENTER); + } + else { + gtk_widget_set_halign (eyes_applet->eyes[i], GTK_ALIGN_CENTER); + gtk_widget_set_valign (eyes_applet->eyes[i], GTK_ALIGN_CENTER); + } + + gtk_widget_realize (eyes_applet->eyes[i]); + + eyes_applet->pointer_last_x[i] = G_MAXINT; + eyes_applet->pointer_last_y[i] = G_MAXINT; + + draw_eye (eyes_applet, i, + eyes_applet->eye_width / 2, + eyes_applet->eye_height / 2); + + } + gtk_widget_show (eyes_applet->hbox); +} + +void +destroy_eyes (EyesApplet *eyes_applet) +{ + gtk_widget_destroy (eyes_applet->hbox); + eyes_applet->hbox = NULL; + + g_free (eyes_applet->eyes); + g_free (eyes_applet->pointer_last_x); + g_free (eyes_applet->pointer_last_y); +} + +static EyesApplet * +create_eyes (MatePanelApplet *applet) +{ + EyesApplet *eyes_applet = g_new0 (EyesApplet, 1); + + eyes_applet->applet = applet; + eyes_applet->vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); + eyes_applet->settings = + mate_panel_applet_settings_new (applet, "org.mate.panel.applet.geyes"); + + gtk_container_add (GTK_CONTAINER (applet), eyes_applet->vbox); + + return eyes_applet; +} + +static void +dispose_cb (GObject *object, EyesApplet *eyes_applet) +{ + g_return_if_fail (eyes_applet); + + g_source_remove (eyes_applet->timeout_id); + if (eyes_applet->hbox) + destroy_eyes (eyes_applet); + eyes_applet->timeout_id = 0; + if (eyes_applet->eye_image) + g_object_unref (eyes_applet->eye_image); + eyes_applet->eye_image = NULL; + if (eyes_applet->pupil_image) + g_object_unref (eyes_applet->pupil_image); + eyes_applet->pupil_image = NULL; + if (eyes_applet->theme_dir) + g_free (eyes_applet->theme_dir); + eyes_applet->theme_dir = NULL; + if (eyes_applet->theme_name) + g_free (eyes_applet->theme_name); + eyes_applet->theme_name = NULL; + if (eyes_applet->eye_filename) + g_free (eyes_applet->eye_filename); + eyes_applet->eye_filename = NULL; + if (eyes_applet->pupil_filename) + g_free (eyes_applet->pupil_filename); + eyes_applet->pupil_filename = NULL; + + if (eyes_applet->prop_box.pbox) + gtk_widget_destroy (eyes_applet->prop_box.pbox); + + if (eyes_applet->settings) + g_object_unref (eyes_applet->settings); + eyes_applet->settings = NULL; + + g_free (eyes_applet); +} + +static void +help_cb (GtkAction *action, + EyesApplet *eyes_applet) +{ + GError *error = NULL; + + gtk_show_uri_on_window (NULL, + "help:mate-geyes", + gtk_get_current_event_time (), + &error); + + if (error) { + GtkWidget *dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, + _("There was an error displaying help: %s"), error->message); + g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (gtk_widget_destroy), NULL); + gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); + gtk_window_set_screen (GTK_WINDOW (dialog), gtk_widget_get_screen (GTK_WIDGET (eyes_applet->applet))); + gtk_widget_show (dialog); + g_error_free (error); + error = NULL; + } +} + + +static const GtkActionEntry geyes_applet_menu_actions [] = { + { "Props", "document-properties", N_("_Preferences"), + NULL, NULL, + G_CALLBACK (properties_cb) }, + { "Help", "help-browser", N_("_Help"), + NULL, NULL, + G_CALLBACK (help_cb) }, + { "About", "help-about", N_("_About"), + NULL, NULL, + G_CALLBACK (about_cb) } +}; + +static void +set_atk_name_description (GtkWidget *widget, const gchar *name, + const gchar *description) +{ + AtkObject *aobj; + + aobj = gtk_widget_get_accessible (widget); + /* Check if gail is loaded */ + if (GTK_IS_ACCESSIBLE (aobj) == FALSE) + return; + + atk_object_set_name (aobj, name); + atk_object_set_description (aobj, description); +} + +static gboolean +geyes_applet_fill (MatePanelApplet *applet) +{ + EyesApplet *eyes_applet; + GtkActionGroup *action_group; + + g_set_application_name (_("Eyes")); + + gtk_window_set_default_icon_name ("mate-eyes-applet"); + mate_panel_applet_set_flags (applet, MATE_PANEL_APPLET_EXPAND_MINOR); + mate_panel_applet_set_background_widget (applet, GTK_WIDGET (applet)); + + eyes_applet = create_eyes (applet); + + eyes_applet->timeout_id = g_timeout_add ( + UPDATE_TIMEOUT, (GSourceFunc) timer_cb, eyes_applet); + + action_group = gtk_action_group_new ("Geyes Applet Actions"); + gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE); + + gtk_action_group_add_actions (action_group, + geyes_applet_menu_actions, + G_N_ELEMENTS (geyes_applet_menu_actions), + eyes_applet); + + mate_panel_applet_setup_menu_from_resource (eyes_applet->applet, + GEYES_RESOURCE_PATH "geyes-applet-menu.xml", + action_group); + + if (mate_panel_applet_get_locked_down (eyes_applet->applet)) { + GtkAction *action; + + action = gtk_action_group_get_action (action_group, "Props"); + gtk_action_set_visible (action, FALSE); + } + g_object_unref (action_group); + + gtk_widget_set_tooltip_text (GTK_WIDGET (eyes_applet->applet), _("Eyes")); + + set_atk_name_description (GTK_WIDGET (eyes_applet->applet), _("Eyes"), + _("The eyes look in the direction of the mouse pointer")); + + g_signal_connect (eyes_applet->vbox, + "dispose", + G_CALLBACK (dispose_cb), + eyes_applet); + + gtk_widget_show_all (GTK_WIDGET (eyes_applet->applet)); + + /* setup here and not in create eyes so the destroy signal is set so + * that when there is an error within loading the theme + * we can emit this signal */ + if (properties_load (eyes_applet) == FALSE) + return FALSE; + + setup_eyes (eyes_applet); + + return TRUE; +} + +static gboolean +geyes_applet_factory (MatePanelApplet *applet, + const gchar *iid, + gpointer data) +{ + gboolean retval = FALSE; + + theme_dirs_create (); + + if (!strcmp (iid, "GeyesApplet")) + retval = geyes_applet_fill (applet); + + if (retval == FALSE) { + exit (-1); + } + + return retval; +} + +MATE_PANEL_APPLET_OUT_PROCESS_FACTORY ("GeyesAppletFactory", + PANEL_TYPE_APPLET, + "geyes", + geyes_applet_factory, + NULL) diff --git a/geyes/src/geyes.h b/geyes/src/geyes.h new file mode 100644 index 00000000..3fb24457 --- /dev/null +++ b/geyes/src/geyes.h @@ -0,0 +1,85 @@ +/* + * Copyright (C) 1999 Dave Camp + * + * 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 of the License, 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef __GEYES_H__ +#define __GEYES_H__ + +#include +#include +#include +#include +#include +#include + +#define MAX_EYES 1000 +typedef struct +{ + GtkWidget *pbox; + + gint selected_row; +} EyesPropertyBox; + +typedef struct +{ + /* Applet */ + MatePanelApplet *applet; + GtkWidget *vbox; + GtkWidget *hbox; + GtkWidget **eyes; + guint timeout_id; + gint *pointer_last_x; + gint *pointer_last_y; + + /* Theme */ + GdkPixbuf *eye_image; + GdkPixbuf *pupil_image; + gchar *theme_dir; + gchar *theme_name; + gchar *eye_filename; + gchar *pupil_filename; + gint num_eyes; + gint eye_height; + gint eye_width; + gint pupil_height; + gint pupil_width; + gint wall_thickness; + + /* Properties */ + EyesPropertyBox prop_box; + + /* Settings */ + GSettings *settings; +} EyesApplet; + +/* eyes.c */ +void setup_eyes (EyesApplet *eyes_applet); + +void destroy_eyes (EyesApplet *eyes_applet); + + +/* theme.c */ +void theme_dirs_create (void); + +int load_theme (EyesApplet *eyes_applet, + const gchar *theme_dir); + +void properties_cb (GtkAction *action, + EyesApplet *eyes_applet); + +#endif diff --git a/geyes/src/themes.c b/geyes/src/themes.c new file mode 100644 index 00000000..6eed8cc9 --- /dev/null +++ b/geyes/src/themes.c @@ -0,0 +1,351 @@ +/* + * Copyright (C) 1999 Dave Camp + * + * 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 of the License, 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "geyes.h" + +#define GET_WIDGET(x) (GTK_WIDGET (gtk_builder_get_object (builder, (x)))) + +#define NUM_THEME_DIRECTORIES 2 + +static char *theme_directories[NUM_THEME_DIRECTORIES]; + +enum { + COL_THEME_DIR = 0, + COL_THEME_NAME, + TOTAL_COLS +}; + +void theme_dirs_create (void) +{ + static gboolean themes_created = FALSE; + + if (themes_created == TRUE) + return; + + theme_directories[0] = g_build_filename(GEYES_THEMES_DIR, NULL); + + theme_directories[1] = g_build_filename(g_get_user_config_dir(), "mate", "geyes-themes", NULL); + + themes_created = TRUE; +} + +static void +parse_theme_file (EyesApplet *eyes_applet, FILE *theme_file) +{ + gchar line_buf [512]; /* prolly overkill */ + gchar *token; + + if (fgets (line_buf, 512, theme_file) == NULL) + printf("fgets error\n"); + + while (!feof (theme_file)) { + token = strtok (line_buf, "="); + if (strncmp (token, "wall-thickness", + strlen ("wall-thickness")) == 0) { + token += strlen ("wall-thickness"); + while (!isdigit (*token)) { + token++; + } + sscanf (token, "%d", &eyes_applet->wall_thickness); + } else if (strncmp (token, "num-eyes", strlen ("num-eyes")) == 0) { + token += strlen ("num-eyes"); + while (!isdigit (*token)) { + token++; + } + sscanf (token, "%d", &eyes_applet->num_eyes); + if (eyes_applet->num_eyes > MAX_EYES) + eyes_applet->num_eyes = MAX_EYES; + } else if (strncmp (token, "eye-pixmap", strlen ("eye-pixmap")) == 0) { + token = strtok (NULL, "\""); + token = strtok (NULL, "\""); + if (eyes_applet->eye_filename != NULL) + g_free (eyes_applet->eye_filename); + eyes_applet->eye_filename = g_strdup_printf ("%s%s", + eyes_applet->theme_dir, + token); + } else if (strncmp (token, "pupil-pixmap", strlen ("pupil-pixmap")) == 0) { + token = strtok (NULL, "\""); + token = strtok (NULL, "\""); + if (eyes_applet->pupil_filename != NULL) + g_free (eyes_applet->pupil_filename); + eyes_applet->pupil_filename + = g_strdup_printf ("%s%s", + eyes_applet->theme_dir, + token); + } + if (fgets (line_buf, 512, theme_file) == NULL) + printf("fgets error\n"); + } +} + +int +load_theme (EyesApplet *eyes_applet, const gchar *theme_dir) +{ + GtkWidget *dialog; + + FILE* theme_file; + gchar *file_name; + + eyes_applet->theme_dir = g_strdup_printf ("%s/", theme_dir); + + file_name = g_strdup_printf("%s%s",theme_dir,"/config"); + theme_file = fopen (file_name, "r"); + g_free (file_name); + if (theme_file == NULL) { + g_free (eyes_applet->theme_dir); + eyes_applet->theme_dir = g_strdup_printf (GEYES_THEMES_DIR "Default-tiny/"); + theme_file = fopen (GEYES_THEMES_DIR "Default-tiny/config", "r"); + } + + /* if it's still NULL we've got a major problem */ + if (theme_file == NULL) { + dialog = gtk_message_dialog_new_with_markup (NULL, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + "%s\n\n%s", + _("Can not launch the eyes applet."), + _("There was a fatal error while trying to load the theme.")); + + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + + gtk_widget_destroy (GTK_WIDGET (eyes_applet->applet)); + + return FALSE; + } + + parse_theme_file (eyes_applet, theme_file); + fclose (theme_file); + + eyes_applet->theme_name = g_strdup (theme_dir); + + if (eyes_applet->eye_image) + g_object_unref (eyes_applet->eye_image); + eyes_applet->eye_image = gdk_pixbuf_new_from_file (eyes_applet->eye_filename, NULL); + if (eyes_applet->pupil_image) + g_object_unref (eyes_applet->pupil_image); + eyes_applet->pupil_image = gdk_pixbuf_new_from_file (eyes_applet->pupil_filename, NULL); + + eyes_applet->eye_height = gdk_pixbuf_get_height (eyes_applet->eye_image); + eyes_applet->eye_width = gdk_pixbuf_get_width (eyes_applet->eye_image); + eyes_applet->pupil_height = gdk_pixbuf_get_height (eyes_applet->pupil_image); + eyes_applet->pupil_width = gdk_pixbuf_get_width (eyes_applet->pupil_image); + + return TRUE; +} + +static void +destroy_theme (EyesApplet *eyes_applet) +{ + /* Dunno about this - to unref or not to unref? */ + if (eyes_applet->eye_image != NULL) { + g_object_unref (eyes_applet->eye_image); + eyes_applet->eye_image = NULL; + } + if (eyes_applet->pupil_image != NULL) { + g_object_unref (eyes_applet->pupil_image); + eyes_applet->pupil_image = NULL; + } + + g_free (eyes_applet->theme_dir); + g_free (eyes_applet->theme_name); +} + +static void +theme_selected_cb (GtkTreeSelection *selection, gpointer data) +{ + EyesApplet *eyes_applet = data; + GtkTreeModel *model; + GtkTreeIter iter; + gchar *theme; + gchar *theme_dir; + + if (!gtk_tree_selection_get_selected (selection, &model, &iter)) + return; + + gtk_tree_model_get (model, &iter, COL_THEME_DIR, &theme, -1); + + g_return_if_fail (theme); + + theme_dir = g_strdup_printf ("%s/", theme); + if (!g_ascii_strncasecmp (theme_dir, eyes_applet->theme_dir, strlen (theme_dir))) { + g_free (theme_dir); + return; + } + g_free (theme_dir); + + destroy_eyes (eyes_applet); + destroy_theme (eyes_applet); + load_theme (eyes_applet, theme); + setup_eyes (eyes_applet); + + g_settings_set_string ( + eyes_applet->settings, "theme-path", theme); + + g_free (theme); +} + +static void +phelp_cb (GtkDialog *dialog) +{ + GError *error = NULL; + + gtk_show_uri_on_window (GTK_WINDOW (dialog), + "help:mate-geyes/geyes-settings", + gtk_get_current_event_time (), + &error); + + if (error) { + GtkWidget *error_dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, + _("There was an error displaying help: %s"), error->message); + g_signal_connect (G_OBJECT (error_dialog), "response", G_CALLBACK (gtk_widget_destroy) , NULL); + gtk_window_set_resizable (GTK_WINDOW (error_dialog), FALSE); + gtk_window_set_screen (GTK_WINDOW (error_dialog), gtk_widget_get_screen (GTK_WIDGET (dialog))); + gtk_widget_show (error_dialog); + g_error_free (error); + error = NULL; + } +} + +static void +presponse_cb (GtkDialog *dialog, gint id, gpointer data) +{ + EyesApplet *eyes_applet = data; + if(id == GTK_RESPONSE_HELP){ + phelp_cb (dialog); + return; + } + + + gtk_widget_destroy (GTK_WIDGET (dialog)); + + eyes_applet->prop_box.pbox = NULL; +} + +void +properties_cb (GtkAction *action, + EyesApplet *eyes_applet) +{ + GtkBuilder *builder; + GtkWidget *tree; + GtkWidget *label; + GtkListStore *model; + GtkTreeViewColumn *column; + GtkCellRenderer *cell; + GtkTreeIter iter; + DIR *dfd; + struct dirent *dp; + int i; +#ifdef PATH_MAX + gchar filename [PATH_MAX]; +#else + gchar *filename; +#endif + + if (eyes_applet->prop_box.pbox) { + gtk_window_set_screen ( + GTK_WINDOW (eyes_applet->prop_box.pbox), + gtk_widget_get_screen (GTK_WIDGET (eyes_applet->applet))); + gtk_window_present (GTK_WINDOW (eyes_applet->prop_box.pbox)); + return; + } + + builder = gtk_builder_new_from_resource (GEYES_RESOURCE_PATH "themes.ui"); + + eyes_applet->prop_box.pbox = GET_WIDGET ("preferences_dialog"); + tree = GET_WIDGET ("themes_treeview"); + label = GET_WIDGET ("select_theme_label"); + + model = gtk_list_store_new (TOTAL_COLS, G_TYPE_STRING, G_TYPE_STRING); + gtk_tree_view_set_model (GTK_TREE_VIEW (tree), GTK_TREE_MODEL (model)); + cell = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes ("not used", cell, + "text", COL_THEME_NAME, NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column); + + if ( ! g_settings_is_writable (eyes_applet->settings, "theme-path")) { + gtk_widget_set_sensitive (tree, FALSE); + gtk_widget_set_sensitive (label, FALSE); + } + + for (i = 0; i < NUM_THEME_DIRECTORIES; i++) { + if ((dfd = opendir (theme_directories[i])) != NULL) { + while ((dp = readdir (dfd)) != NULL) { + if (dp->d_name[0] != '.') { + gchar *theme_dir; + gchar *theme_name; +#ifdef PATH_MAX + strcpy (filename, + theme_directories[i]); + strcat (filename, dp->d_name); +#else + asprintf (&filename, theme_directories[i], dp->d_name); +#endif + theme_dir = g_strdup_printf ("%s/", filename); + theme_name = g_path_get_basename (filename); + + gtk_list_store_append (model, &iter); + gtk_list_store_set (model, &iter, + COL_THEME_DIR, &filename, + COL_THEME_NAME, theme_name, + -1); + + if (!g_ascii_strncasecmp (eyes_applet->theme_dir, theme_dir, strlen (theme_dir))) { + GtkTreePath *path; + path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), + &iter); + gtk_tree_view_set_cursor (GTK_TREE_VIEW (tree), + path, + NULL, + FALSE); + gtk_tree_path_free (path); + } + g_free (theme_name); + g_free (theme_dir); + } + } + closedir (dfd); + } + } +#ifndef PATH_MAX + g_free (filename); +#endif + g_object_unref (model); + + /* signals */ + gtk_builder_add_callback_symbols (builder, + "on_preferences_dialog_response", G_CALLBACK (presponse_cb), + "on_themes_treeselection_changed", G_CALLBACK (theme_selected_cb), + NULL); + gtk_builder_connect_signals (builder, eyes_applet); + + g_object_unref (builder); + + gtk_widget_show_all (eyes_applet->prop_box.pbox); + + return; +} diff --git a/geyes/themes.c b/geyes/themes.c deleted file mode 100644 index 6eed8cc9..00000000 --- a/geyes/themes.c +++ /dev/null @@ -1,351 +0,0 @@ -/* - * Copyright (C) 1999 Dave Camp - * - * 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 of the License, 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include "geyes.h" - -#define GET_WIDGET(x) (GTK_WIDGET (gtk_builder_get_object (builder, (x)))) - -#define NUM_THEME_DIRECTORIES 2 - -static char *theme_directories[NUM_THEME_DIRECTORIES]; - -enum { - COL_THEME_DIR = 0, - COL_THEME_NAME, - TOTAL_COLS -}; - -void theme_dirs_create (void) -{ - static gboolean themes_created = FALSE; - - if (themes_created == TRUE) - return; - - theme_directories[0] = g_build_filename(GEYES_THEMES_DIR, NULL); - - theme_directories[1] = g_build_filename(g_get_user_config_dir(), "mate", "geyes-themes", NULL); - - themes_created = TRUE; -} - -static void -parse_theme_file (EyesApplet *eyes_applet, FILE *theme_file) -{ - gchar line_buf [512]; /* prolly overkill */ - gchar *token; - - if (fgets (line_buf, 512, theme_file) == NULL) - printf("fgets error\n"); - - while (!feof (theme_file)) { - token = strtok (line_buf, "="); - if (strncmp (token, "wall-thickness", - strlen ("wall-thickness")) == 0) { - token += strlen ("wall-thickness"); - while (!isdigit (*token)) { - token++; - } - sscanf (token, "%d", &eyes_applet->wall_thickness); - } else if (strncmp (token, "num-eyes", strlen ("num-eyes")) == 0) { - token += strlen ("num-eyes"); - while (!isdigit (*token)) { - token++; - } - sscanf (token, "%d", &eyes_applet->num_eyes); - if (eyes_applet->num_eyes > MAX_EYES) - eyes_applet->num_eyes = MAX_EYES; - } else if (strncmp (token, "eye-pixmap", strlen ("eye-pixmap")) == 0) { - token = strtok (NULL, "\""); - token = strtok (NULL, "\""); - if (eyes_applet->eye_filename != NULL) - g_free (eyes_applet->eye_filename); - eyes_applet->eye_filename = g_strdup_printf ("%s%s", - eyes_applet->theme_dir, - token); - } else if (strncmp (token, "pupil-pixmap", strlen ("pupil-pixmap")) == 0) { - token = strtok (NULL, "\""); - token = strtok (NULL, "\""); - if (eyes_applet->pupil_filename != NULL) - g_free (eyes_applet->pupil_filename); - eyes_applet->pupil_filename - = g_strdup_printf ("%s%s", - eyes_applet->theme_dir, - token); - } - if (fgets (line_buf, 512, theme_file) == NULL) - printf("fgets error\n"); - } -} - -int -load_theme (EyesApplet *eyes_applet, const gchar *theme_dir) -{ - GtkWidget *dialog; - - FILE* theme_file; - gchar *file_name; - - eyes_applet->theme_dir = g_strdup_printf ("%s/", theme_dir); - - file_name = g_strdup_printf("%s%s",theme_dir,"/config"); - theme_file = fopen (file_name, "r"); - g_free (file_name); - if (theme_file == NULL) { - g_free (eyes_applet->theme_dir); - eyes_applet->theme_dir = g_strdup_printf (GEYES_THEMES_DIR "Default-tiny/"); - theme_file = fopen (GEYES_THEMES_DIR "Default-tiny/config", "r"); - } - - /* if it's still NULL we've got a major problem */ - if (theme_file == NULL) { - dialog = gtk_message_dialog_new_with_markup (NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - "%s\n\n%s", - _("Can not launch the eyes applet."), - _("There was a fatal error while trying to load the theme.")); - - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - - gtk_widget_destroy (GTK_WIDGET (eyes_applet->applet)); - - return FALSE; - } - - parse_theme_file (eyes_applet, theme_file); - fclose (theme_file); - - eyes_applet->theme_name = g_strdup (theme_dir); - - if (eyes_applet->eye_image) - g_object_unref (eyes_applet->eye_image); - eyes_applet->eye_image = gdk_pixbuf_new_from_file (eyes_applet->eye_filename, NULL); - if (eyes_applet->pupil_image) - g_object_unref (eyes_applet->pupil_image); - eyes_applet->pupil_image = gdk_pixbuf_new_from_file (eyes_applet->pupil_filename, NULL); - - eyes_applet->eye_height = gdk_pixbuf_get_height (eyes_applet->eye_image); - eyes_applet->eye_width = gdk_pixbuf_get_width (eyes_applet->eye_image); - eyes_applet->pupil_height = gdk_pixbuf_get_height (eyes_applet->pupil_image); - eyes_applet->pupil_width = gdk_pixbuf_get_width (eyes_applet->pupil_image); - - return TRUE; -} - -static void -destroy_theme (EyesApplet *eyes_applet) -{ - /* Dunno about this - to unref or not to unref? */ - if (eyes_applet->eye_image != NULL) { - g_object_unref (eyes_applet->eye_image); - eyes_applet->eye_image = NULL; - } - if (eyes_applet->pupil_image != NULL) { - g_object_unref (eyes_applet->pupil_image); - eyes_applet->pupil_image = NULL; - } - - g_free (eyes_applet->theme_dir); - g_free (eyes_applet->theme_name); -} - -static void -theme_selected_cb (GtkTreeSelection *selection, gpointer data) -{ - EyesApplet *eyes_applet = data; - GtkTreeModel *model; - GtkTreeIter iter; - gchar *theme; - gchar *theme_dir; - - if (!gtk_tree_selection_get_selected (selection, &model, &iter)) - return; - - gtk_tree_model_get (model, &iter, COL_THEME_DIR, &theme, -1); - - g_return_if_fail (theme); - - theme_dir = g_strdup_printf ("%s/", theme); - if (!g_ascii_strncasecmp (theme_dir, eyes_applet->theme_dir, strlen (theme_dir))) { - g_free (theme_dir); - return; - } - g_free (theme_dir); - - destroy_eyes (eyes_applet); - destroy_theme (eyes_applet); - load_theme (eyes_applet, theme); - setup_eyes (eyes_applet); - - g_settings_set_string ( - eyes_applet->settings, "theme-path", theme); - - g_free (theme); -} - -static void -phelp_cb (GtkDialog *dialog) -{ - GError *error = NULL; - - gtk_show_uri_on_window (GTK_WINDOW (dialog), - "help:mate-geyes/geyes-settings", - gtk_get_current_event_time (), - &error); - - if (error) { - GtkWidget *error_dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - _("There was an error displaying help: %s"), error->message); - g_signal_connect (G_OBJECT (error_dialog), "response", G_CALLBACK (gtk_widget_destroy) , NULL); - gtk_window_set_resizable (GTK_WINDOW (error_dialog), FALSE); - gtk_window_set_screen (GTK_WINDOW (error_dialog), gtk_widget_get_screen (GTK_WIDGET (dialog))); - gtk_widget_show (error_dialog); - g_error_free (error); - error = NULL; - } -} - -static void -presponse_cb (GtkDialog *dialog, gint id, gpointer data) -{ - EyesApplet *eyes_applet = data; - if(id == GTK_RESPONSE_HELP){ - phelp_cb (dialog); - return; - } - - - gtk_widget_destroy (GTK_WIDGET (dialog)); - - eyes_applet->prop_box.pbox = NULL; -} - -void -properties_cb (GtkAction *action, - EyesApplet *eyes_applet) -{ - GtkBuilder *builder; - GtkWidget *tree; - GtkWidget *label; - GtkListStore *model; - GtkTreeViewColumn *column; - GtkCellRenderer *cell; - GtkTreeIter iter; - DIR *dfd; - struct dirent *dp; - int i; -#ifdef PATH_MAX - gchar filename [PATH_MAX]; -#else - gchar *filename; -#endif - - if (eyes_applet->prop_box.pbox) { - gtk_window_set_screen ( - GTK_WINDOW (eyes_applet->prop_box.pbox), - gtk_widget_get_screen (GTK_WIDGET (eyes_applet->applet))); - gtk_window_present (GTK_WINDOW (eyes_applet->prop_box.pbox)); - return; - } - - builder = gtk_builder_new_from_resource (GEYES_RESOURCE_PATH "themes.ui"); - - eyes_applet->prop_box.pbox = GET_WIDGET ("preferences_dialog"); - tree = GET_WIDGET ("themes_treeview"); - label = GET_WIDGET ("select_theme_label"); - - model = gtk_list_store_new (TOTAL_COLS, G_TYPE_STRING, G_TYPE_STRING); - gtk_tree_view_set_model (GTK_TREE_VIEW (tree), GTK_TREE_MODEL (model)); - cell = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("not used", cell, - "text", COL_THEME_NAME, NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column); - - if ( ! g_settings_is_writable (eyes_applet->settings, "theme-path")) { - gtk_widget_set_sensitive (tree, FALSE); - gtk_widget_set_sensitive (label, FALSE); - } - - for (i = 0; i < NUM_THEME_DIRECTORIES; i++) { - if ((dfd = opendir (theme_directories[i])) != NULL) { - while ((dp = readdir (dfd)) != NULL) { - if (dp->d_name[0] != '.') { - gchar *theme_dir; - gchar *theme_name; -#ifdef PATH_MAX - strcpy (filename, - theme_directories[i]); - strcat (filename, dp->d_name); -#else - asprintf (&filename, theme_directories[i], dp->d_name); -#endif - theme_dir = g_strdup_printf ("%s/", filename); - theme_name = g_path_get_basename (filename); - - gtk_list_store_append (model, &iter); - gtk_list_store_set (model, &iter, - COL_THEME_DIR, &filename, - COL_THEME_NAME, theme_name, - -1); - - if (!g_ascii_strncasecmp (eyes_applet->theme_dir, theme_dir, strlen (theme_dir))) { - GtkTreePath *path; - path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), - &iter); - gtk_tree_view_set_cursor (GTK_TREE_VIEW (tree), - path, - NULL, - FALSE); - gtk_tree_path_free (path); - } - g_free (theme_name); - g_free (theme_dir); - } - } - closedir (dfd); - } - } -#ifndef PATH_MAX - g_free (filename); -#endif - g_object_unref (model); - - /* signals */ - gtk_builder_add_callback_symbols (builder, - "on_preferences_dialog_response", G_CALLBACK (presponse_cb), - "on_themes_treeselection_changed", G_CALLBACK (theme_selected_cb), - NULL); - gtk_builder_connect_signals (builder, eyes_applet); - - g_object_unref (builder); - - gtk_widget_show_all (eyes_applet->prop_box.pbox); - - return; -} diff --git a/geyes/themes.ui b/geyes/themes.ui deleted file mode 100644 index 70409f3b..00000000 --- a/geyes/themes.ui +++ /dev/null @@ -1,171 +0,0 @@ - - - - - - True - False - help-browser - - - True - False - window-close - - - False - 12 - Eyes Preferences - 300 - 200 - mate-eyes-applet - dialog - - - - False - vertical - 2 - - - False - end - - - _Help - True - True - True - image1 - True - True - - - True - True - 0 - - - - - _Close - True - True - True - True - True - image2 - True - True - - - True - True - 1 - - - - - False - False - 0 - - - - - True - False - True - 0 - none - - - True - False - 12 - - - True - False - 6 - 6 - True - vertical - 6 - - - True - False - start - _Select a theme: - True - themes_treeview - - - False - True - 0 - - - - - True - True - True - True - never - in - - - True - True - True - True - False - False - - - - - - - - - - False - True - 1 - - - - - - - - - True - False - Themes - - - - - - - - False - True - 1 - - - - - - button1 - button2 - - - - - - -- cgit v1.2.1