diff --git a/annotate.h b/annotate.h index 830c8a22..ed8c7b79 100644 --- a/annotate.h +++ b/annotate.h @@ -19,10 +19,6 @@ #include "main.h" #include -struct DBusException: public std::exception { - virtual const char* what() const throw() { return "Connection to DBus failed"; } -}; - class Annotate : public Trace { DBusGConnection *bus; DBusGProxy *draw_proxy; diff --git a/fire.cc b/fire.cc new file mode 100644 index 00000000..6e2ec8a6 --- /dev/null +++ b/fire.cc @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2008, Thomas Jaeger + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#include "fire.h" +#include +#include + +Fire::Fire() { + const char *ofc = "org.freedesktop.compiz"; + GError *error = 0; + bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); + if (!bus) { + g_error_free(error); + throw DBusException(); + } + point_proxy = dbus_g_proxy_new_for_name(bus, ofc, "/org/freedesktop/compiz/firepaint/allscreens/add_point", ofc); + clear_proxy = dbus_g_proxy_new_for_name(bus, ofc, "/org/freedesktop/compiz/firepaint/allscreens/clear_key", ofc); +} + +void Fire::add_point(float x, float y) { + dbus_g_proxy_call_no_reply(point_proxy, "activate", + G_TYPE_STRING, "root", G_TYPE_INT, gint(ROOT), + G_TYPE_STRING, "x", G_TYPE_DOUBLE, gdouble(x), + G_TYPE_STRING, "y", G_TYPE_DOUBLE, gdouble(y), + G_TYPE_INVALID); +} + +void Fire::draw(Point p, Point q) { + float dist = hypot(p.x-q.x, p.y-q.y); + leftover -= dist; + while (leftover < 0.01) { + add_point(q.x + (q.x-p.x)*leftover/dist, q.y + (q.y-p.y)*leftover/dist); + leftover += 5.0; + } +} +void Fire::timeout() { + dbus_g_proxy_call_no_reply(clear_proxy, "activate", + G_TYPE_STRING, "root", G_TYPE_INT, gint(ROOT), + G_TYPE_INVALID); +} diff --git a/fire.h b/fire.h new file mode 100644 index 00000000..989f2b5b --- /dev/null +++ b/fire.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2008, Thomas Jaeger + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#ifndef __FIRE_H__ +#define __FIRE_H__ +#include "util.h" +#include "trace.h" +#include "main.h" +#include + +class Fire : public Trace, public Timeout { + DBusGConnection *bus; + DBusGProxy *point_proxy; + DBusGProxy *clear_proxy; + float leftover; + + virtual void draw(Point p, Point q); + void add_point(float, float); + virtual void start_() { leftover = 0; } + virtual void end_() { set_timeout(333); } + virtual void timeout(); +public: + Fire(); +}; + +#endif diff --git a/gui.glade b/gui.glade index 2d47f138..60178a3e 100644 --- a/gui.glade +++ b/gui.glade @@ -1,6 +1,6 @@ - + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK @@ -300,7 +300,8 @@ than this many pixels away from the original position Standard XShape None -Annotate +Annotate +Fire 1 diff --git a/main.cc b/main.cc index 9c0d7fdf..3e797904 100644 --- a/main.cc +++ b/main.cc @@ -22,6 +22,7 @@ #include "prefdb.h" #include "trace.h" #include "annotate.h" +#include "fire.h" #include "copy.h" #include "grabber.h" @@ -109,6 +110,13 @@ Trace *init_trace() { printf("Error: %s\n", e.what()); return new Trivial(); } + case TraceFire: + try { + return new Fire(); + } catch (DBusException e) { + printf("Error: %s\n", e.what()); + return new Trivial(); + } default: return new Copy(); } diff --git a/prefdb.h b/prefdb.h index 5bf4d02b..c8d3b5b2 100644 --- a/prefdb.h +++ b/prefdb.h @@ -22,8 +22,7 @@ #include "var.h" -enum TraceType { TraceStandard = 0, TraceShape = 1, TraceNone = 2, TraceAnnotate = 3 }; -const int trace_n = 4; +enum TraceType { TraceStandard, TraceShape, TraceNone, TraceAnnotate, TraceFire, TraceN }; class ButtonInfo { friend class boost::serialization::access; diff --git a/prefs.cc b/prefs.cc index 73b1470c..4183894b 100644 --- a/prefs.cc +++ b/prefs.cc @@ -128,6 +128,12 @@ Prefs::Prefs() { add_exception->signal_clicked().connect(sigc::mem_fun(*this, &Prefs::on_add)); remove_exception->signal_clicked().connect(sigc::mem_fun(*this, &Prefs::on_remove)); + if (!experimental) { + Glib::RefPtr trace_model = Glib::RefPtr::cast_dynamic(trace->get_model()); + Gtk::TreeIter i = trace_model->children().end(); + trace_model->erase(--i); + + } trace->signal_changed().connect(sigc::mem_fun(*this, &Prefs::on_trace_changed)); trace->set_active(prefs.trace.get()); @@ -259,7 +265,7 @@ extern void update_trace(); //TODO void Prefs::on_trace_changed() { TraceType type = (TraceType) trace->get_active_row_number(); - if (type >= trace_n) + if (type >= TraceN) return; if (prefs.trace.get() == type) return; diff --git a/trace.h b/trace.h index b1519e13..e9312915 100644 --- a/trace.h +++ b/trace.h @@ -17,10 +17,15 @@ #define __TRACE_H__ #include +#include #define WIDTH 4 #define TRACE_COLOR 0x980101 +struct DBusException: public std::exception { + virtual const char* what() const throw() { return "Connection to DBus failed"; } +}; + class Trace { public: struct Point { float x; float y; };