Skip to content

Commit

Permalink
lots of fixes
Browse files Browse the repository at this point in the history
darcs-hash:20080617022814-a887e-74f7265943e8be8ae1a5e75593c78d9c791e1e07.gz
  • Loading branch information
thjaeger committed Jun 17, 2008
1 parent 3867ca6 commit 09c3726
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 52 deletions.
6 changes: 2 additions & 4 deletions grabber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,9 @@ void Grabber::get_button() {

void Grabber::fake_button() {
ButtonInfo bi = prefs().click.get();
int b = bi.button;
if ((int)b == -1)
if (bi.special == SPECIAL_IGNORE)
return;
if (b == 0)
b = button;
int b = (bi.special == SPECIAL_DEFAULT) ? button : bi.button;
suspend();
bi.press();
XTestFakeButtonEvent(dpy, b, True, CurrentTime);
Expand Down
33 changes: 8 additions & 25 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 Mon Jun 16 19:26:57 2008 -->
<!--Generated with glade3 3.4.5 on Mon Jun 16 20:40:59 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 @@ -245,20 +245,14 @@ None</property>
<property name="label_xalign">0</property>
<property name="shadow_type">GTK_SHADOW_NONE</property>
<child>
<widget class="GtkAlignment" id="alignment6">
<widget class="GtkAlignment" id="alignment_click">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="top_padding">4</property>
<property name="bottom_padding">4</property>
<property name="left_padding">12</property>
<child>
<widget class="GtkComboBox" id="combo_click">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="items" translatable="yes">Default
Ignore
Select...</property>
</widget>
<placeholder/>
</child>
</widget>
</child>
Expand All @@ -285,25 +279,14 @@ Select...</property>
<property name="label_xalign">0</property>
<property name="shadow_type">GTK_SHADOW_NONE</property>
<child>
<widget class="GtkAlignment" id="alignment7">
<widget class="GtkAlignment" id="alignment_stroke_click">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="top_padding">4</property>
<property name="bottom_padding">4</property>
<property name="left_padding">12</property>
<child>
<widget class="GtkComboBox" id="combo_stroke_click">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="items" translatable="yes">Abort Stroke
Ignore
Button 1
Button 2
Button 3
Button 8
Button 9
Select...</property>
</widget>
<placeholder/>
</child>
</widget>
</child>
Expand Down Expand Up @@ -848,12 +831,12 @@ Please place your mouse or pen in the box below and press the button that you wa
<property name="items" translatable="yes">Button 1
Button 2
Button 3
Button 8
Button 9
Button 4
Button 5
Button 6
Button 7</property>
Button 7
Button 8
Button 9</property>
</widget>
<packing>
<property name="position">4</property>
Expand Down
6 changes: 4 additions & 2 deletions main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -394,15 +394,17 @@ void Main::run() {
if (grabber->xinput) {
if (!emulate)
emulate_info = prefs().stroke_click.get();
if (emulate_info.button == 0)
if (emulate_info.special == SPECIAL_IGNORE)
break;
trace->end();
cur.reset();
if (emulate_info.button == -1)
if (emulate_info.special == SPECIAL_DEFAULT)
break;
for (unsigned int i = 1; i <= 5; i++)
if (i == ev.xbutton.button || (ev.xbutton.state & (1 << (i+7))))
XTestFakeButtonEvent(dpy, i, False, CurrentTime);
if (grabber->button > 5)
XTestFakeButtonEvent(dpy, grabber->button, False, CurrentTime);
if (emulate_grabbed) {
XUngrabButton(dpy, AnyButton, AnyModifier, ROOT);
emulate_grabbed = false;
Expand Down
6 changes: 3 additions & 3 deletions prefdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include <X11/Xlib.h>

const double pref_p_default = 0.5;
const ButtonInfo pref_button_default = { Button2, 0 };
const ButtonInfo pref_click_default = { 0, 0 };
const ButtonInfo pref_stroke_click_default = { -1, 0 };
const ButtonInfo pref_button_default = { Button2, 0, 0 };
const ButtonInfo pref_click_default = { 0, 0, SPECIAL_DEFAULT };
const ButtonInfo pref_stroke_click_default = { 0, 0, SPECIAL_DEFAULT };
const int pref_delay_default = 0;

PrefDB::PrefDB() :
Expand Down
7 changes: 7 additions & 0 deletions prefdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,25 @@
enum TraceType { TraceStandard, TraceShape, TraceNone };
const int trace_n = 3;

#define SPECIAL_DEFAULT 1
#define SPECIAL_IGNORE 2

struct ButtonInfo {
guint button;
guint state;
int special;
void press();
void release();
private:
friend class boost::serialization::access;
template<class Archive> void serialize(Archive & ar, const unsigned int version) {
ar & button;
ar & state;
if (version == 0) return;
ar & special;
}
};
BOOST_CLASS_VERSION(ButtonInfo, 1)

extern const double pref_p_default;
extern const int pref_delay_default;
Expand Down
117 changes: 100 additions & 17 deletions prefs.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "prefs.h"
#include "prefdb.h"
#include "win.h"
#include "main.h"

Expand All @@ -14,21 +13,46 @@ void usage() {}

Glib::ustring get_button_text(ButtonInfo &bi);

Prefs::Prefs(Win *parent_) : good_state(true), parent(parent_), q(sigc::mem_fun(*this, &Prefs::on_selected)) {
Prefs::Prefs(Win *parent_) :
good_state(true), parent(parent_), q(sigc::mem_fun(*this, &Prefs::on_selected)),
have_last_click(false), have_last_stroke_click(false)
{
Gtk::Button *bbutton, *add_exception, *remove_exception, *button_default_p, *button_default_delay;
parent->widgets->get_widget("button_add_exception", add_exception);
parent->widgets->get_widget("button_button", bbutton);
parent->widgets->get_widget("button_default_delay", button_default_delay);
parent->widgets->get_widget("button_default_p", button_default_p);
parent->widgets->get_widget("button_remove_exception", remove_exception);
parent->widgets->get_widget("combo_click", click);
parent->widgets->get_widget("combo_stroke_click", stroke_click);
parent->widgets->get_widget("combo_trace", trace);
parent->widgets->get_widget("label_button", blabel);
parent->widgets->get_widget("treeview_exceptions", tv);
parent->widgets->get_widget("scale_p", scale_p);
parent->widgets->get_widget("spin_delay", spin_delay);

// I love glade.
Gtk::Alignment *align;

parent->widgets->get_widget("alignment_click", align);
click = Gtk::manage(new Gtk::ComboBoxText());
align->add(*click);
click->append_text("Default");
click->append_text("Ignore");
click->append_text("Select...");
click->show();

parent->widgets->get_widget("alignment_stroke_click", align);
stroke_click = Gtk::manage(new Gtk::ComboBoxText());
align->add(*stroke_click);
stroke_click->append_text("Abort Stroke");
stroke_click->append_text("Ignore");
stroke_click->append_text("Button 1");
stroke_click->append_text("Button 2");
stroke_click->append_text("Button 3");
stroke_click->append_text("Button 8");
stroke_click->append_text("Button 9");
stroke_click->append_text("Select...");
stroke_click->show();

tm = Gtk::ListStore::create(cols);
tv->set_model(tm);
tv->append_column("WM__CLASS name", cols.col);
Expand Down Expand Up @@ -103,22 +127,27 @@ class SelectButton {
widgets->get_widget("toggle_control", toggle_control);
widgets->get_widget("toggle_super", toggle_super);
widgets->get_widget("select_button", select_button);
select_button->set_active(bi.button - 1);
toggle_shift->set_active(bi.state & GDK_SHIFT_MASK);
toggle_control->set_active(bi.state & GDK_CONTROL_MASK);
toggle_alt->set_active(bi.state & GDK_MOD1_MASK);
toggle_super->set_active(bi.state & GDK_MOD4_MASK);
select_button->set_active(bi.special ? -1 : bi.button-1);
toggle_shift->set_active(!bi.special && (bi.state & GDK_SHIFT_MASK));
toggle_control->set_active(!bi.special && (bi.state & GDK_CONTROL_MASK));
toggle_alt->set_active(!bi.special && (bi.state & GDK_MOD1_MASK));
toggle_super->set_active(!bi.special && (bi.state & GDK_MOD4_MASK));
if (!eventbox->get_children().size()) {
eventbox->set_events(Gdk::BUTTON_PRESS_MASK);
eventbox->signal_button_press_event().connect(sigc::mem_fun(*this, &SelectButton::on_button_press));

Glib::RefPtr<Gdk::Pixbuf> pb = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB,true,8,400,200);
pb->fill(0x808080ff);
WIDGET(Gtk::Image, box, pb);
eventbox->add(box);
box.show();
}
handler = eventbox->signal_button_press_event().connect(sigc::mem_fun(*this, &SelectButton::on_button_press));
}

~SelectButton() {
handler.disconnect();
}

bool run() {
send(P_SUSPEND_GRAB);
int response;
Expand Down Expand Up @@ -164,6 +193,7 @@ class SelectButton {
Gtk::EventBox *eventbox;
Gtk::ToggleButton *toggle_shift, *toggle_control, *toggle_alt, *toggle_super;
Gtk::ComboBox *select_button;
sigc::connection handler;
};

void Prefs::on_select_button() {
Expand All @@ -174,6 +204,7 @@ void Prefs::on_select_button() {
Ref<ButtonInfo> ref(prefs().button);
ref->button = sb.event.button;
ref->state = sb.event.state;
ref->special = 0;
}
send(P_REGRAB);
set_button_label();
Expand All @@ -184,24 +215,43 @@ bool set_by_me = false; //TODO: Come up with something better

void Prefs::show_click() {
Ref<ButtonInfo> ref(prefs().click);
if ((int)ref->button <= 0) {
if (ref->special) {
set_by_me = true;
click->set_active(-ref->button);
click->set_active(ref->special - 1);
set_by_me = false;
return;
}
click->set_title(get_button_text(*ref));
set_by_me = true;
if (have_last_click) {
click->remove_text(get_button_text(last_click));
}
last_click = *ref;
click->remove_text("Select...");
click->append_text(get_button_text(last_click));
click->append_text("Select...");
click->set_active(2);
set_by_me = false;
have_last_click = true;
}

void Prefs::on_click_changed() {
if (set_by_me)
return;
int n = click->get_active_row_number();
if (n == -1)
return;
if (n <= 1) {
{
Ref<ButtonInfo> ref(prefs().click);
ref->state = 0;
ref->button = -n;
ref->special = n + 1;
}
write();
return;
}
if (n == 2 && have_last_click) {
{
Ref<ButtonInfo> ref(prefs().click);
*ref = last_click;
}
write();
return;
Expand All @@ -213,6 +263,7 @@ void Prefs::on_click_changed() {
Ref<ButtonInfo> ref(prefs().click);
ref->button = sb.event.button;
ref->state = sb.event.state;
ref->special = 0;
}
write();
}
Expand All @@ -221,9 +272,9 @@ void Prefs::on_click_changed() {

void Prefs::show_stroke_click() {
Ref<ButtonInfo> ref(prefs().stroke_click);
if ((int)ref->button <= 0) {
if (ref->special) {
set_by_me = true;
stroke_click->set_active(1+ref->button);
stroke_click->set_active(ref->special-1);
set_by_me = false;
return;
}
Expand All @@ -240,17 +291,39 @@ void Prefs::show_stroke_click() {
return;
}
stroke_click->set_title(get_button_text(*ref));
set_by_me = true;
if (have_last_stroke_click) {
stroke_click->remove_text(get_button_text(last_stroke_click));
}
last_stroke_click = *ref;
stroke_click->remove_text("Select...");
stroke_click->append_text(get_button_text(last_stroke_click));
stroke_click->append_text("Select...");
stroke_click->set_active(7);
set_by_me = false;
have_last_stroke_click = true;
}

void Prefs::on_stroke_click_changed() {
if (set_by_me)
return;
int n = stroke_click->get_active_row_number();
if (n == -1)
return;
if (n <= 1) {
{
Ref<ButtonInfo> ref(prefs().stroke_click);
ref->special = n + 1;
}
write();
return;
}
if (n <= 4) {
{
Ref<ButtonInfo> ref(prefs().stroke_click);
ref->state = 0;
ref->button = n-1;
ref->special = 0;
}
write();
return;
Expand All @@ -260,6 +333,15 @@ void Prefs::on_stroke_click_changed() {
Ref<ButtonInfo> ref(prefs().stroke_click);
ref->state = 0;
ref->button = n+3;
ref->special = 0;
}
write();
return;
}
if (n == 7 && have_last_stroke_click) {
{
Ref<ButtonInfo> ref(prefs().stroke_click);
*ref = last_stroke_click;
}
write();
return;
Expand All @@ -271,6 +353,7 @@ void Prefs::on_stroke_click_changed() {
Ref<ButtonInfo> ref(prefs().stroke_click);
ref->button = sb.event.button;
ref->state = sb.event.state;
ref->special = 0;
}
write();
}
Expand Down
Loading

0 comments on commit 09c3726

Please sign in to comment.