Skip to content

Commit

Permalink
xi detection, unrelated ui changes
Browse files Browse the repository at this point in the history
darcs-hash:20080709005538-a887e-ac4d9423c571438a3f92743bd316d7ee7411157a.gz
  • Loading branch information
thjaeger committed Jul 9, 2008
1 parent 7bd205a commit d9e39e4
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 7 deletions.
39 changes: 38 additions & 1 deletion 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 Fri Jun 27 13:58:51 2008 -->
<!--Generated with glade3 3.4.5 on Tue Jul 8 17:08:50 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 @@ -271,6 +271,43 @@ than this many pixels away from the original position.</property>
<property name="position">2</property>
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox4">
<property name="visible">True</property>
<child>
<widget class="GtkCheckButton" id="check_ignore_grab">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Accept gestures when menus are shown (experimental)</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLinkButton" id="linkbutton2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="has_tooltip">True</property>
<property name="label" translatable="yes">(See Documentation)</property>
<property name="relief">GTK_RELIEF_NONE</property>
<property name="response_id">0</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="position">3</property>
</packing>
</child>
</widget>
</child>
</widget>
Expand Down
31 changes: 28 additions & 3 deletions main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -376,18 +376,32 @@ class ActionXiHandler : public Handler {

Trace::Point orig;

Bool is_xi_press(Display *dpy, XEvent *ev, XPointer arg) {
Time *t = (Time *)arg;
if (!grabber->xinput)
return false;
if (!grabber->is_button_down(ev->type))
return false;
XDeviceButtonEvent* bev = (XDeviceButtonEvent *)ev;
if (bev->button != grabber->button)
return false;
return bev->time == *t;
}

class StrokeHandler : public Handler {
RPreStroke cur;
bool is_gesture;
float speed;
Time last_t;
int last_x, last_y;
bool repeated;
bool have_xi;

RStroke finish(guint b) {
trace->end();
XFlush(dpy);
XAllowEvents(dpy, AsyncPointer, CurrentTime);
if (have_xi)
XAllowEvents(dpy, AsyncPointer, CurrentTime);
if (!is_gesture)
cur->clear();
if (b && prefs().advanced_ignore.get())
Expand All @@ -396,6 +410,8 @@ class StrokeHandler : public Handler {
}

bool calc_speed(int x, int y, Time t) {
if (!have_xi)
return false;
int dt = t - last_t;
float c = exp(dt/-250.0);
if (dt) {
Expand Down Expand Up @@ -489,14 +505,23 @@ class StrokeHandler : public Handler {
parent->replace_child(0);
}
public:
StrokeHandler(int x, int y, Time t) : is_gesture(false), speed(0.1), last_t(t), last_x(x), last_y(y), repeated(false) {
StrokeHandler(int x, int y, Time t) : is_gesture(false), speed(0.1), last_t(t), last_x(x), last_y(y),
repeated(false), have_xi(false) {
orig.x = x; orig.y = y;
cur = PreStroke::create();
cur->add(x,y,t);
if (xinput_pressed)
have_xi = true;
XEvent ev;
if (!have_xi)
have_xi = XCheckIfEvent(dpy, &ev, &is_xi_press, (XPointer)&t);
if (!have_xi)
XAllowEvents(dpy, AsyncPointer, CurrentTime);
}
~StrokeHandler() {
trace->end();
XAllowEvents(dpy, AsyncPointer, CurrentTime);
if (have_xi)
XAllowEvents(dpy, AsyncPointer, CurrentTime);
}
virtual std::string name() { return "Stroke"; }
};
Expand Down
3 changes: 2 additions & 1 deletion prefdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ PrefDB::PrefDB() :
button(pref_button_default),
trace(TraceShape),
advanced_ignore(false),
radius(pref_radius_default)
radius(pref_radius_default),
ignore_grab(false)
{}

bool PrefDB::write() const {
Expand Down
5 changes: 4 additions & 1 deletion prefdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class PrefDB {
if (version <= 1) return;
{ Ref<bool> ref(advanced_ignore); ar & *ref; }
{ Ref<int> ref(radius); ar & *ref; }
if (version <= 3) return;
{ Ref<bool> ref(ignore_grab); ar & *ref; }
}
std::string filename;
public:
Expand All @@ -67,12 +69,13 @@ class PrefDB {
Lock<TraceType> trace;
Lock<bool> advanced_ignore;
Lock<int> radius;
Lock<bool> ignore_grab;

void read();
bool write() const;
};

BOOST_CLASS_VERSION(PrefDB, 3)
BOOST_CLASS_VERSION(PrefDB, 4)

typedef Ref<std::set<std::string> > RPrefEx;

Expand Down
9 changes: 9 additions & 0 deletions prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Prefs::Prefs(Win *parent_) :
parent->widgets->get_widget("check_advanced_ignore", advanced_ignore);
parent->widgets->get_widget("spin_radius", spin_radius);
parent->widgets->get_widget("button_default_radius", button_default_radius);
parent->widgets->get_widget("check_ignore_grab", ignore_grab);

tm = Gtk::ListStore::create(cols);
tv->set_model(tm);
Expand All @@ -43,6 +44,9 @@ Prefs::Prefs(Win *parent_) :
advanced_ignore->signal_toggled().connect(sigc::mem_fun(*this, &Prefs::on_advanced_ignore_changed));
advanced_ignore->set_active(prefs().advanced_ignore.get());

ignore_grab->signal_toggled().connect(sigc::mem_fun(*this, &Prefs::on_ignore_grab_changed));
ignore_grab->set_active(prefs().ignore_grab.get());

double p = prefs().p.get();
scale_p->set_value(p);
scale_p->signal_value_changed().connect(sigc::mem_fun(*this, &Prefs::on_p_changed));
Expand Down Expand Up @@ -193,6 +197,11 @@ void Prefs::on_advanced_ignore_changed() {
write();
}

void Prefs::on_ignore_grab_changed() {
prefs().ignore_grab.set(ignore_grab->get_active());
write();
}

void Prefs::on_p_changed() {
prefs().p.set(scale_p->get_value());
write();
Expand Down
3 changes: 2 additions & 1 deletion prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Prefs {
void on_select_button();
void on_trace_changed();
void on_advanced_ignore_changed();
void on_ignore_grab_changed();

struct SelectRow;

Expand All @@ -50,7 +51,7 @@ class Prefs {
Gtk::HScale* scale_p;
Gtk::SpinButton *spin_radius;
Gtk::Label* blabel;
Gtk::CheckButton *advanced_ignore;
Gtk::CheckButton *advanced_ignore, *ignore_grab;
};

#endif

0 comments on commit d9e39e4

Please sign in to comment.