* Commit new eyes plugin.
(Old svn revision: 2018)
This commit is contained in:
commit
2dc8facea7
90 changed files with 2701 additions and 0 deletions
35
panel-plugin/Makefile.am
Normal file
35
panel-plugin/Makefile.am
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
plugindir = $(libexecdir)/xfce4/panel-plugins
|
||||
plugin_PROGRAMS = xfce4-eyes-plugin
|
||||
|
||||
xfce4_eyes_plugin_SOURCES = \
|
||||
eyes.h \
|
||||
eyes.c \
|
||||
themes.h \
|
||||
themes.c
|
||||
|
||||
xfce4_eyes_plugin_CFLAGS = \
|
||||
-I$(top_srcdir) \
|
||||
$(LIBXFCEGUI4_CFLAGS) \
|
||||
$(LIBXFCE4PANEL_CFLAGS) \
|
||||
-DPACKAGE_LOCALE_DIR=\"$(localedir)\" \
|
||||
-DTHEMESDIR=\"$(datadir)/xfce4/eyes/themes\"
|
||||
|
||||
xfce4_eyes_plugin_LDADD = \
|
||||
$(LIBXFCE4PANEL_LIBS) \
|
||||
$(LIBXFCEGUI4_LIBS)
|
||||
|
||||
desktopdir = $(datadir)/xfce4/panel-plugins
|
||||
desktop_in_in_files = eyes.desktop.in.in
|
||||
desktop_in_files = $(desktop_in_in_files:.desktop.in.in=.desktop.in)
|
||||
%.desktop.in: %.desktop.in.in
|
||||
sed -e "s,\@libexecdir\@,$(libexecdir),g" < $< > $@
|
||||
desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
|
||||
@INTLTOOL_DESKTOP_RULE@
|
||||
|
||||
EXTRA_DIST = \
|
||||
$(desktop_in_in_files)
|
||||
|
||||
CLEANFILES = \
|
||||
$(desktop_in_files) \
|
||||
$(desktop_DATA)
|
||||
|
||||
541
panel-plugin/eyes.c
Normal file
541
panel-plugin/eyes.c
Normal file
|
|
@ -0,0 +1,541 @@
|
|||
/*
|
||||
* Copyright (c) Benedikt Meurer <benedikt.meurer@unix-ag.uni-siegen.de>>
|
||||
* Copyright (c) Danny Milosavljevic <danny_milo@gmx.net>
|
||||
* Copyright (c) Dave Camp
|
||||
* Copyright (c) Davyd Madeley <davyd@madeley.id.au>
|
||||
* Copyright (c) Nick Schermer <nick@xfce.org>
|
||||
*
|
||||
* 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., 59 Temple
|
||||
* Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MATH_H
|
||||
#include <math.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <libxfce4util/libxfce4util.h>
|
||||
#include <libxfcegui4/libxfcegui4.h>
|
||||
|
||||
#include "eyes.h"
|
||||
#include "themes.h"
|
||||
|
||||
/* for xml: */
|
||||
#define EYES_ROOT "Eyes"
|
||||
#define DEFAULTTHEME "Tango"
|
||||
#define UPDATE_TIMEOUT 100
|
||||
|
||||
|
||||
/*****************************
|
||||
*** Eyes Plugin Functions ***
|
||||
*****************************/
|
||||
static void
|
||||
calculate_pupil_xy (EyesPlugin *eyes_applet,
|
||||
gint x, gint y,
|
||||
gint *pupil_x, gint *pupil_y, GtkWidget* widget)
|
||||
{
|
||||
double sina;
|
||||
double cosa;
|
||||
double h;
|
||||
double temp;
|
||||
double nx, ny;
|
||||
|
||||
gfloat xalign, yalign;
|
||||
gint width, height;
|
||||
|
||||
width = GTK_WIDGET(widget)->allocation.width;
|
||||
height = GTK_WIDGET(widget)->allocation.height;
|
||||
gtk_misc_get_alignment(GTK_MISC(widget), &xalign, &yalign);
|
||||
|
||||
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 || abs (h)
|
||||
< (abs (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 (EyesPlugin *eyes,
|
||||
gint eye_num,
|
||||
gint pupil_x,
|
||||
gint pupil_y)
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
GdkRectangle rect, r1, r2;
|
||||
|
||||
pixbuf = gdk_pixbuf_copy (eyes->eye_image);
|
||||
r1.x = pupil_x - eyes->pupil_width / 2;
|
||||
r1.y = pupil_y - eyes->pupil_height / 2;
|
||||
r1.width = eyes->pupil_width;
|
||||
r1.height = eyes->pupil_height;
|
||||
r2.x = 0;
|
||||
r2.y = 0;
|
||||
r2.width = eyes->eye_width;
|
||||
r2.height = eyes->eye_height;
|
||||
gdk_rectangle_intersect (&r1, &r2, &rect);
|
||||
gdk_pixbuf_composite (eyes->pupil_image, pixbuf,
|
||||
rect.x,
|
||||
rect.y,
|
||||
rect.width,
|
||||
rect.height,
|
||||
pupil_x - eyes->pupil_width / 2,
|
||||
pupil_y - eyes->pupil_height / 2, 1.0, 1.0,
|
||||
GDK_INTERP_BILINEAR,
|
||||
255);
|
||||
gtk_image_set_from_pixbuf (GTK_IMAGE (eyes->eyes[eye_num]),
|
||||
pixbuf);
|
||||
g_object_unref (G_OBJECT (pixbuf));
|
||||
}
|
||||
|
||||
|
||||
|
||||
static gint
|
||||
timer_cb(EyesPlugin *eyes)
|
||||
{
|
||||
gint x, y;
|
||||
gint pupil_x, pupil_y;
|
||||
gint i;
|
||||
|
||||
for (i = 0; i < eyes->num_eyes; i++)
|
||||
{
|
||||
if (GTK_WIDGET_REALIZED(eyes->eyes[i]))
|
||||
{
|
||||
gdk_window_get_pointer(eyes->eyes[i]->window, &x, &y, NULL);
|
||||
|
||||
if ((x != eyes->pointer_last_x[i]) || (y != eyes->pointer_last_y[i]))
|
||||
{
|
||||
|
||||
calculate_pupil_xy (eyes, x, y, &pupil_x, &pupil_y, eyes->eyes[i]);
|
||||
draw_eye (eyes, i, pupil_x, pupil_y);
|
||||
|
||||
eyes->pointer_last_x[i] = x;
|
||||
eyes->pointer_last_y[i] = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
properties_load(EyesPlugin *eyes)
|
||||
{
|
||||
gchar *path;
|
||||
|
||||
if (eyes->active_theme)
|
||||
path = g_build_filename(THEMESDIR, eyes->active_theme, NULL);
|
||||
else
|
||||
path = g_build_filename(THEMESDIR, DEFAULTTHEME, NULL);
|
||||
|
||||
load_theme(eyes, path);
|
||||
|
||||
g_free(path);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
setup_eyes(EyesPlugin *eyes)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (eyes->hbox != NULL)
|
||||
{
|
||||
gtk_widget_destroy(eyes->hbox);
|
||||
eyes->hbox = NULL;
|
||||
}
|
||||
|
||||
eyes->hbox = gtk_hbox_new(FALSE, 0);
|
||||
gtk_container_add(GTK_CONTAINER(eyes->align), GTK_WIDGET(eyes->hbox));
|
||||
|
||||
eyes->eyes = g_new0 (GtkWidget *, eyes->num_eyes);
|
||||
eyes->pointer_last_x = g_new0 (gint, eyes->num_eyes);
|
||||
eyes->pointer_last_y = g_new0 (gint, eyes->num_eyes);
|
||||
|
||||
for (i = 0; i < eyes->num_eyes; i++)
|
||||
{
|
||||
eyes->eyes[i] = gtk_image_new ();
|
||||
|
||||
gtk_widget_set_size_request(GTK_WIDGET(eyes->eyes[i]),
|
||||
eyes->eye_width,
|
||||
eyes->eye_height);
|
||||
|
||||
gtk_widget_show(eyes->eyes[i]);
|
||||
|
||||
gtk_box_pack_start(GTK_BOX(eyes->hbox), eyes->eyes[i],
|
||||
FALSE, FALSE, 0);
|
||||
|
||||
if ((eyes->num_eyes != 1) && (i == 0))
|
||||
gtk_misc_set_alignment (GTK_MISC (eyes->eyes[i]), 1.0, 0.5);
|
||||
else if ((eyes->num_eyes != 1) && (i == eyes->num_eyes - 1))
|
||||
gtk_misc_set_alignment (GTK_MISC (eyes->eyes[i]), 0.0, 0.5);
|
||||
else
|
||||
gtk_misc_set_alignment (GTK_MISC (eyes->eyes[i]), 0.5, 0.5);
|
||||
|
||||
eyes->pointer_last_x[i] = G_MAXINT;
|
||||
eyes->pointer_last_y[i] = G_MAXINT;
|
||||
|
||||
draw_eye (eyes, i,
|
||||
eyes->eye_width / 2,
|
||||
eyes->eye_height / 2);
|
||||
}
|
||||
|
||||
gtk_widget_show(eyes->hbox);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static gboolean
|
||||
eyes_applet_fill(EyesPlugin *eyes)
|
||||
{
|
||||
gtk_widget_show_all(GTK_WIDGET(eyes->align));
|
||||
|
||||
if (eyes->timeout_id == 0)
|
||||
{
|
||||
eyes->timeout_id = g_timeout_add (UPDATE_TIMEOUT,
|
||||
(GtkFunction)timer_cb, eyes);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*************************
|
||||
*** Properties Dialog ***
|
||||
*************************/
|
||||
static void
|
||||
eyes_properties_dialog_response (GtkWidget *dlg,
|
||||
gint response,
|
||||
EyesPlugin *eyes)
|
||||
{
|
||||
xfce_panel_plugin_unblock_menu (eyes->plugin);
|
||||
|
||||
gtk_widget_destroy (dlg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
combobox_changed (GtkComboBox *combobox,
|
||||
EyesPlugin *eyes)
|
||||
{
|
||||
gchar *selected = gtk_combo_box_get_active_text (combobox);
|
||||
|
||||
if (eyes->active_theme)
|
||||
g_free (eyes->active_theme);
|
||||
|
||||
eyes->active_theme = g_strdup (selected);
|
||||
g_free (selected);
|
||||
|
||||
properties_load(eyes);
|
||||
setup_eyes(eyes);
|
||||
eyes_applet_fill(eyes);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
eyes_properties_dialog (XfcePanelPlugin *plugin,
|
||||
EyesPlugin *eyes)
|
||||
{
|
||||
GtkWidget *dlg, *hbox, *label, *combobox;
|
||||
GDir *dir;
|
||||
gint i;
|
||||
gchar *current;
|
||||
const gchar *entry;
|
||||
|
||||
xfce_panel_plugin_block_menu (plugin);
|
||||
|
||||
dlg = xfce_titled_dialog_new_with_buttons (_("Eyes"),
|
||||
GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (plugin))),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
|
||||
GTK_STOCK_CLOSE, GTK_RESPONSE_OK,
|
||||
NULL);
|
||||
|
||||
gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_CENTER);
|
||||
gtk_window_set_icon_name (GTK_WINDOW (dlg), "xfce4-settings");
|
||||
|
||||
g_signal_connect (dlg, "response", G_CALLBACK (eyes_properties_dialog_response),
|
||||
eyes);
|
||||
|
||||
hbox = gtk_hbox_new(FALSE, 6);
|
||||
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), hbox, FALSE, FALSE, 0);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
|
||||
|
||||
label = gtk_label_new_with_mnemonic (_("_Select a theme:"));
|
||||
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
|
||||
|
||||
combobox = gtk_combo_box_new_text ();
|
||||
gtk_box_pack_start (GTK_BOX (hbox), combobox, FALSE, TRUE, 0);
|
||||
|
||||
if (eyes->active_theme)
|
||||
current = g_strdup (eyes->active_theme);
|
||||
else
|
||||
current = g_strdup (DEFAULTTHEME);
|
||||
|
||||
if ((dir = g_dir_open(THEMESDIR, 0, NULL)) == NULL)
|
||||
{
|
||||
gtk_combo_box_append_text (GTK_COMBO_BOX (combobox), current);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; (entry = g_dir_read_name(dir)) != NULL; i++)
|
||||
{
|
||||
gtk_combo_box_append_text (GTK_COMBO_BOX (combobox), entry);
|
||||
|
||||
if (strcmp (entry, current) == 0)
|
||||
gtk_combo_box_set_active (GTK_COMBO_BOX(combobox), i);
|
||||
}
|
||||
|
||||
g_dir_close(dir);
|
||||
}
|
||||
|
||||
g_free (current);
|
||||
|
||||
gtk_label_set_mnemonic_widget (GTK_LABEL (label), combobox);
|
||||
|
||||
g_signal_connect(G_OBJECT(combobox), "changed",
|
||||
G_CALLBACK(combobox_changed), eyes);
|
||||
|
||||
gtk_widget_show_all (dlg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/******************************
|
||||
*** Panel Plugin Functions ***
|
||||
******************************/
|
||||
static void
|
||||
eyes_free_data(XfcePanelPlugin *plugin,
|
||||
EyesPlugin *eyes)
|
||||
{
|
||||
g_return_if_fail(plugin != NULL);
|
||||
g_return_if_fail(eyes != NULL);
|
||||
|
||||
if (eyes->timeout_id != 0)
|
||||
g_source_remove (eyes->timeout_id);
|
||||
|
||||
g_free (eyes->eyes);
|
||||
g_free (eyes->pointer_last_x);
|
||||
g_free (eyes->pointer_last_y);
|
||||
|
||||
if (eyes->active_theme != NULL)
|
||||
g_free (eyes->active_theme);
|
||||
|
||||
if (eyes->eye_image != NULL)
|
||||
g_object_unref (G_OBJECT (eyes->eye_image));
|
||||
|
||||
if (eyes->pupil_image != NULL)
|
||||
g_object_unref (G_OBJECT (eyes->pupil_image));
|
||||
|
||||
if (eyes->theme_dir != NULL)
|
||||
g_free(eyes->theme_dir);
|
||||
|
||||
if (eyes->theme_name != NULL)
|
||||
g_free(eyes->theme_name);
|
||||
|
||||
if (eyes->eye_filename != NULL)
|
||||
g_free(eyes->eye_filename);
|
||||
|
||||
if (eyes->pupil_filename != NULL)
|
||||
g_free(eyes->pupil_filename);
|
||||
|
||||
gtk_widget_destroy(eyes->align);
|
||||
g_free(eyes);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static gboolean
|
||||
eyes_set_size (XfcePanelPlugin *plugin,
|
||||
int size)
|
||||
{
|
||||
if (xfce_panel_plugin_get_orientation (plugin) ==
|
||||
GTK_ORIENTATION_HORIZONTAL)
|
||||
{
|
||||
gtk_widget_set_size_request (GTK_WIDGET (plugin),
|
||||
-1, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_set_size_request (GTK_WIDGET (plugin),
|
||||
size, -1);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
eyes_orientation_changed (XfcePanelPlugin *plugin,
|
||||
GtkOrientation orientation,
|
||||
EyesPlugin *eyes)
|
||||
{
|
||||
if (orientation == GTK_ORIENTATION_VERTICAL)
|
||||
gtk_alignment_set (GTK_ALIGNMENT (eyes->align), 0.5, 0.5, 0.0, 1.0);
|
||||
else
|
||||
gtk_alignment_set (GTK_ALIGNMENT (eyes->align), 0.5, 0.5, 1.0, 0.0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
eyes_read_rc_file (XfcePanelPlugin *plugin,
|
||||
EyesPlugin *eyes)
|
||||
{
|
||||
XfceRc *rc;
|
||||
gchar *file;
|
||||
gchar const *tmp;
|
||||
|
||||
if (eyes->active_theme != NULL)
|
||||
{
|
||||
g_free (eyes->active_theme);
|
||||
eyes->active_theme = NULL;
|
||||
}
|
||||
|
||||
if ((file = xfce_panel_plugin_lookup_rc_file (plugin)) != NULL)
|
||||
{
|
||||
rc = xfce_rc_simple_open (file, TRUE);
|
||||
g_free (file);
|
||||
|
||||
if (rc != NULL)
|
||||
{
|
||||
tmp = xfce_rc_read_entry (rc, "theme", DEFAULTTHEME);
|
||||
|
||||
if (tmp != NULL)
|
||||
eyes->active_theme = g_strdup (tmp);
|
||||
|
||||
xfce_rc_close (rc);
|
||||
}
|
||||
}
|
||||
|
||||
if (eyes->active_theme == NULL)
|
||||
eyes->active_theme = g_strdup (DEFAULTTHEME);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
eyes_write_rc_file (XfcePanelPlugin *plugin,
|
||||
EyesPlugin *eyes)
|
||||
{
|
||||
gchar *file;
|
||||
XfceRc *rc;
|
||||
|
||||
if (!(file = xfce_panel_plugin_save_location (plugin, TRUE)))
|
||||
return;
|
||||
|
||||
rc = xfce_rc_simple_open (file, FALSE);
|
||||
g_free (file);
|
||||
|
||||
if (!rc)
|
||||
return;
|
||||
|
||||
if (eyes->active_theme != NULL)
|
||||
xfce_rc_write_entry (rc, "theme", eyes->active_theme);
|
||||
|
||||
xfce_rc_close (rc);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static EyesPlugin *
|
||||
eyes_plugin_new (XfcePanelPlugin* plugin)
|
||||
{
|
||||
EyesPlugin *eyes;
|
||||
|
||||
eyes = g_new0(EyesPlugin, 1);
|
||||
|
||||
eyes->plugin = plugin;
|
||||
|
||||
eyes->ebox = gtk_event_box_new ();
|
||||
gtk_widget_show(GTK_WIDGET(eyes->ebox));
|
||||
|
||||
eyes->align = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
|
||||
|
||||
gtk_widget_show(GTK_WIDGET(eyes->align));
|
||||
|
||||
gtk_container_add(GTK_CONTAINER(eyes->ebox), GTK_WIDGET(eyes->align));
|
||||
|
||||
eyes_read_rc_file (plugin, eyes);
|
||||
|
||||
properties_load(eyes);
|
||||
setup_eyes(eyes);
|
||||
eyes_applet_fill(eyes);
|
||||
|
||||
return eyes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
eyes_construct (XfcePanelPlugin *plugin)
|
||||
{
|
||||
EyesPlugin *eyes;
|
||||
|
||||
xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
|
||||
|
||||
eyes = eyes_plugin_new (plugin);
|
||||
|
||||
g_signal_connect (plugin, "orientation-changed",
|
||||
G_CALLBACK (eyes_orientation_changed), eyes);
|
||||
|
||||
g_signal_connect (plugin, "size-changed",
|
||||
G_CALLBACK (eyes_set_size), NULL);
|
||||
|
||||
g_signal_connect (plugin, "free-data",
|
||||
G_CALLBACK (eyes_free_data), eyes);
|
||||
|
||||
g_signal_connect (plugin, "save",
|
||||
G_CALLBACK (eyes_write_rc_file), eyes);
|
||||
|
||||
xfce_panel_plugin_menu_show_configure (plugin);
|
||||
g_signal_connect (plugin, "configure-plugin",
|
||||
G_CALLBACK (eyes_properties_dialog), eyes);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (plugin), eyes->ebox);
|
||||
|
||||
xfce_panel_plugin_add_action_widget (plugin, eyes->ebox);
|
||||
}
|
||||
|
||||
XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL (eyes_construct);
|
||||
7
panel-plugin/eyes.desktop.in.in
Normal file
7
panel-plugin/eyes.desktop.in.in
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
[Xfce Panel]
|
||||
Type=X-XFCE-PanelPlugin
|
||||
Encoding=UTF-8
|
||||
_Name=Eyes
|
||||
_Comment=Eyes that spy on you
|
||||
Icon=xfce4-eyes
|
||||
X-XFCE-Exec=@libexecdir@/xfce4/panel-plugins/xfce4-eyes-plugin
|
||||
43
panel-plugin/eyes.h
Normal file
43
panel-plugin/eyes.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
|
||||
|
||||
|
||||
#ifndef __EYES_H__
|
||||
#define __EYES_H__
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <libxfce4panel/xfce-panel-plugin.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
XfcePanelPlugin *plugin;
|
||||
|
||||
GtkWidget *ebox;
|
||||
|
||||
/* Properties */
|
||||
gchar *active_theme;
|
||||
|
||||
/* Plugin */
|
||||
GtkWidget *align;
|
||||
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;
|
||||
}
|
||||
EyesPlugin;
|
||||
|
||||
#endif /* __EYES_H__ */
|
||||
127
panel-plugin/themes.c
Normal file
127
panel-plugin/themes.c
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
* Copyright (C) 1999 Dave Camp <dave@davec.dhs.org>
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <dirent.h>
|
||||
#include <limits.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include "eyes.h"
|
||||
|
||||
gchar *theme_directories[] = {
|
||||
THEMESDIR
|
||||
};
|
||||
#define NUM_THEME_DIRECTORIES 1
|
||||
|
||||
static void
|
||||
parse_theme_file (EyesPlugin *eyes, FILE *theme_file)
|
||||
{
|
||||
gchar line_buf [512]; /* prolly overkill */
|
||||
gchar *token;
|
||||
fgets (line_buf, 512, theme_file);
|
||||
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->wall_thickness);
|
||||
}
|
||||
else if (strncmp (token, "num-eyes", strlen ("num-eyes")) == 0)
|
||||
{
|
||||
token += strlen ("num-eyes");
|
||||
while (!isdigit (*token))
|
||||
{
|
||||
token++;
|
||||
}
|
||||
sscanf (token, "%d", &eyes->num_eyes);
|
||||
}
|
||||
else if (strncmp (token, "eye-pixmap", strlen ("eye-pixmap")) == 0)
|
||||
{
|
||||
token = strtok (NULL, "\"");
|
||||
token = strtok (NULL, "\"");
|
||||
if (eyes->eye_filename != NULL)
|
||||
g_free (eyes->eye_filename);
|
||||
eyes->eye_filename = g_strdup_printf ("%s%s",
|
||||
eyes->theme_dir,
|
||||
token);
|
||||
}
|
||||
else if (strncmp (token, "pupil-pixmap", strlen ("pupil-pixmap")) == 0)
|
||||
{
|
||||
token = strtok (NULL, "\"");
|
||||
token = strtok (NULL, "\"");
|
||||
if (eyes->pupil_filename != NULL)
|
||||
g_free (eyes->pupil_filename);
|
||||
eyes->pupil_filename
|
||||
= g_strdup_printf ("%s%s",
|
||||
eyes->theme_dir,
|
||||
token);
|
||||
}
|
||||
fgets (line_buf, 512, theme_file);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
load_theme (EyesPlugin *eyes,
|
||||
const gchar *theme_dir)
|
||||
{
|
||||
FILE* theme_file;
|
||||
gchar *file_name;
|
||||
|
||||
eyes->theme_dir = g_strdup_printf ("%s/", theme_dir);
|
||||
|
||||
file_name = g_strdup_printf("%s%s",theme_dir,"/config");
|
||||
theme_file = fopen (file_name, "r");
|
||||
if (theme_file == NULL) {
|
||||
g_error ("Unable to open theme file.");
|
||||
}
|
||||
|
||||
parse_theme_file (eyes, theme_file);
|
||||
fclose (theme_file);
|
||||
|
||||
eyes->theme_name = g_strdup (theme_dir);
|
||||
|
||||
if (eyes->eye_image)
|
||||
g_object_unref (eyes->eye_image);
|
||||
|
||||
eyes->eye_image = gdk_pixbuf_new_from_file (eyes->eye_filename, NULL);
|
||||
|
||||
if (eyes->pupil_image)
|
||||
g_object_unref (eyes->pupil_image);
|
||||
|
||||
eyes->pupil_image = gdk_pixbuf_new_from_file (eyes->pupil_filename, NULL);
|
||||
|
||||
eyes->eye_height = gdk_pixbuf_get_height (eyes->eye_image);
|
||||
eyes->eye_width = gdk_pixbuf_get_width (eyes->eye_image);
|
||||
eyes->pupil_height = gdk_pixbuf_get_height (eyes->pupil_image);
|
||||
eyes->pupil_width = gdk_pixbuf_get_width (eyes->pupil_image);
|
||||
|
||||
g_free (file_name);
|
||||
|
||||
}
|
||||
8
panel-plugin/themes.h
Normal file
8
panel-plugin/themes.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef __THEMES_H__
|
||||
#define __THEMES_H__
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
void
|
||||
load_theme (EyesPlugin *eyes, const gchar *theme_dir);
|
||||
|
||||
#endif /* __THEMES_H__ */
|
||||
Reference in a new issue