Skip to content

Commit

Permalink
fire plugin
Browse files Browse the repository at this point in the history
darcs-hash:20080812032021-485ad-28e519830ac9d9c0dcfe9b89624218a00a07312c.gz
  • Loading branch information
thjaeger committed Aug 12, 2008
1 parent 36d3d67 commit 003b660
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 9 deletions.
4 changes: 0 additions & 4 deletions annotate.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
#include "main.h"
#include <dbus/dbus-glib.h>

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;
Expand Down
52 changes: 52 additions & 0 deletions fire.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2008, Thomas Jaeger <[email protected]>
*
* 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 <X11/Xutil.h>
#include <math.h>

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);
}
38 changes: 38 additions & 0 deletions fire.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2008, Thomas Jaeger <[email protected]>
*
* 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 <dbus/dbus-glib.h>

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
5 changes: 3 additions & 2 deletions gui.glade
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.5 on Sun Aug 10 06:13:05 2008 -->
<!--Generated with glade3 3.4.5 on Mon Aug 11 12:54:40 2008 -->
<glade-interface>
<widget class="GtkWindow" id="main">
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
Expand Down Expand Up @@ -300,7 +300,8 @@ than this many pixels away from the original position</property>
<property name="items" translatable="yes">Standard
XShape
None
Annotate</property>
Annotate
Fire</property>
</widget>
<packing>
<property name="position">1</property>
Expand Down
8 changes: 8 additions & 0 deletions main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "prefdb.h"
#include "trace.h"
#include "annotate.h"
#include "fire.h"
#include "copy.h"
#include "grabber.h"

Expand Down Expand Up @@ -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();
}
Expand Down
3 changes: 1 addition & 2 deletions prefdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Gtk::ListStore> trace_model = Glib::RefPtr<Gtk::ListStore>::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());

Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@
#define __TRACE_H__

#include <X11/Xlib.h>
#include <exception>

#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; };
Expand Down

0 comments on commit 003b660

Please sign in to comment.