Skip to content

Commit

Permalink
Update to c++11
Browse files Browse the repository at this point in the history
  • Loading branch information
thjaeger committed Mar 22, 2014
1 parent d14b274 commit 30a879f
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 55 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ po/??_??
po/POTFILES.in
po/*.pot
easystroke.desktop
.clang_complete
16 changes: 12 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ LOCALEDIR= $(PREFIX)/share/locale
DFLAGS =
OFLAGS = -O2
AOFLAGS = -O3
STROKEFLAGS = -Wall -std=c99 $(DFLAGS)
CXXFLAGS = -Wall $(DFLAGS) -DLOCALEDIR=\"$(LOCALEDIR)\" `pkg-config gtkmm-3.0 dbus-glib-1 --cflags`
CFLAGS = -Wall $(DFLAGS) -DLOCALEDIR=\"$(LOCALEDIR)\" `pkg-config gtk+-3.0 --cflags` -DGETTEXT_PACKAGE='"easystroke"'
STROKEFLAGS = -Wall -std=c11 $(DFLAGS)
CXXSTD = -std=c++11
INCLUDES = $(shell pkg-config gtkmm-3.0 dbus-glib-1 --cflags)
CXXFLAGS = $(CXXSTD) -Wall $(DFLAGS) -DLOCALEDIR=\"$(LOCALEDIR)\" $(INCLUDES)
CFLAGS = -std=c11 -Wall $(DFLAGS) -DLOCALEDIR=\"$(LOCALEDIR)\" $(INCLUDES) -DGETTEXT_PACKAGE='"easystroke"'
LDFLAGS = $(DFLAGS)

LIBS = $(DFLAGS) -lboost_serialization -lX11 -lXext -lXi -lXfixes -lXtst `pkg-config gtkmm-3.0 dbus-glib-1 --libs`
Expand Down Expand Up @@ -51,7 +53,7 @@ DIST = easystroke-$(VERSION)

all: $(BINARY) $(MOFILES)

.PHONY: all clean translate update-translations compile-translations
.PHONY: all clean translate update-translations compile-translations complete

clean:
$(RM) $(OFILES) $(BINARY) $(GENFILES) $(DEPFILES) $(MANPAGE) $(GZFILES) po/*.pot
Expand Down Expand Up @@ -146,3 +148,9 @@ tmp/$(DIST): $(GIT)
$(DIST).tar.gz: tmp/$(DIST)
tar -czf $@ -C tmp/ $(DIST)
$(RM) -r tmp

complete: .clang_complete

.clang_complete: Makefile
@echo $(CXXSTD) > $@
@$(foreach inc,$(INCLUDES),echo $(inc) >> $@;)
5 changes: 3 additions & 2 deletions actiondb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <iostream>
#include <fstream>
#include <string>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/map.hpp>
Expand Down Expand Up @@ -121,7 +122,7 @@ void Command::run() {
pid_t pid = fork();
switch (pid) {
case 0:
execlp("/bin/sh", "sh", "-c", cmd.c_str(), NULL);
execlp("/bin/sh", "sh", "-c", cmd.c_str(), nullptr);
exit(1);
case -1:
printf(_("Error: can't execute command \"%s\": fork() failed\n"), cmd.c_str());
Expand All @@ -142,7 +143,7 @@ const Glib::ustring Button::get_label() const {

const Glib::ustring Misc::get_label() const { return _(types[type]); }

const char *Misc::types[5] = { N_("None"), N_("Unminimize"), N_("Show/Hide"), N_("Disable (Enable)"), NULL };
const char *Misc::types[5] = { N_("None"), N_("Unminimize"), N_("Show/Hide"), N_("Disable (Enable)"), nullptr };

template<class Archive> void ActionListDiff::serialize(Archive & ar, const unsigned int version) {
ar & deleted;
Expand Down
14 changes: 7 additions & 7 deletions actions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ Actions::Actions() :
int i = 0;
while (Misc::types[i]) i++;
CellRendererTextish *arg_renderer = cell_renderer_textish_new_with_items ((gchar**)Misc::types, i);
GtkTreeViewColumn *col_arg = gtk_tree_view_column_new_with_attributes(_("Details"), GTK_CELL_RENDERER (arg_renderer), "text", cols.arg.index(), NULL);
GtkTreeViewColumn *col_arg = gtk_tree_view_column_new_with_attributes(_("Details"), GTK_CELL_RENDERER (arg_renderer), "text", cols.arg.index(), nullptr);
gtk_tree_view_append_column(tv.gobj(), col_arg);

gtk_tree_view_column_set_cell_data_func (col_arg, GTK_CELL_RENDERER (arg_renderer), on_actions_cell_data_arg, this, NULL);
gtk_tree_view_column_set_cell_data_func (col_arg, GTK_CELL_RENDERER (arg_renderer), on_actions_cell_data_arg, this, nullptr);
gtk_tree_view_column_set_resizable(col_arg, true);
g_object_set(arg_renderer, "editable", true, NULL);
g_object_set(arg_renderer, "editable", true, nullptr);
g_signal_connect(arg_renderer, "key-edited", G_CALLBACK(on_actions_accel_edited), this);
g_signal_connect(arg_renderer, "combo-edited", G_CALLBACK(on_actions_combo_edited), this);
g_signal_connect(arg_renderer, "edited", G_CALLBACK(on_actions_text_edited), this);
Expand Down Expand Up @@ -262,7 +262,7 @@ void Actions::on_cell_data_arg(GtkCellRenderer *cell, gchar *path) {
Gtk::TreeModel::iterator iter = tm->get_iter(path);
bool bold = (*iter)[cols.action_bold];
bool deactivated = (*iter)[cols.deactivated];
g_object_set(cell, "sensitive", !deactivated, "weight", bold ? 700 : 400, NULL);
g_object_set(cell, "sensitive", !deactivated, "weight", bold ? 700 : 400, nullptr);
CellRendererTextish *renderer = CELL_RENDERER_TEXTISH (cell);
if (!renderer)
return;
Expand Down Expand Up @@ -309,7 +309,7 @@ bool Actions::AppsStore::row_drop_possible_vfunc(const Gtk::TreeModel::Path &des
if (model != parent->tm)
return false;
Gtk::TreeIter dest_iter = parent->apps_model->get_iter(dest);
ActionListDiff *actions = dest_iter ? (*dest_iter)[parent->ca.actions] : (ActionListDiff *)NULL;
ActionListDiff *actions = dest_iter ? (*dest_iter)[parent->ca.actions] : (ActionListDiff *)nullptr;
return actions && actions != parent->action_list;
}

Expand All @@ -322,7 +322,7 @@ bool Actions::AppsStore::drag_data_received_vfunc(const Gtk::TreeModel::Path &de
return false;
Unique *src_id = (*parent->tm->get_iter(src))[parent->cols.id];
Gtk::TreeIter dest_iter = parent->apps_model->get_iter(dest);
ActionListDiff *actions = dest_iter ? (*dest_iter)[parent->ca.actions] : (ActionListDiff *)NULL;
ActionListDiff *actions = dest_iter ? (*dest_iter)[parent->ca.actions] : (ActionListDiff *)nullptr;
if (!actions || actions == parent->action_list)
return false;
Glib::RefPtr<Gtk::TreeSelection> sel = parent->tv.get_selection();
Expand Down Expand Up @@ -752,7 +752,7 @@ void Actions::on_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewCo
}
RStrokeInfo si = action_list->get_info(row[cols.id]);
if (si)
del->set_sensitive(si->strokes.size());
del->set_sensitive(si->strokes.size() != 0);

OnStroke ps(this, dialog, row);
stroke_action.reset(new sigc::slot<void, RStroke>(sigc::mem_fun(ps, &OnStroke::delayed_run)));
Expand Down
2 changes: 1 addition & 1 deletion gesture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ int Stroke::compare(RStroke a, RStroke b, double &score) {
}
return -1;
}
double cost = stroke_compare(a->stroke.get(), b->stroke.get(), NULL, NULL);
double cost = stroke_compare(a->stroke.get(), b->stroke.get(), nullptr, nullptr);
if (cost >= stroke_infinity)
return -1;
score = MAX(1.0 - 2.5*cost, 0.0);
Expand Down
4 changes: 2 additions & 2 deletions grabber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ void Grabber::new_device(XIDeviceInfo *info) {
}
}

Grabber::XiDevice::XiDevice(Grabber *parent, XIDeviceInfo *info) : absolute(false), proximity_axis(-1), scale_x(1.0), scale_y(1.0), num_buttons(0) {
Grabber::XiDevice::XiDevice(Grabber *parent, XIDeviceInfo *info) : absolute(false), active(true), proximity_axis(-1), scale_x(1.0), scale_y(1.0), num_buttons(0) {
static XAtom PROXIMITY(AXIS_LABEL_PROP_ABS_DISTANCE);
dev = info->deviceid;
name = info->name;
Expand Down Expand Up @@ -398,7 +398,7 @@ Grabber::XiDevice::XiDevice(Grabber *parent, XIDeviceInfo *info) : absolute(fals

Grabber::XiDevice *Grabber::get_xi_dev(int id) {
DeviceMap::iterator i = xi_devs.find(id);
return i == xi_devs.end() ? NULL : i->second.get();
return i == xi_devs.end() ? nullptr : i->second.get();
}

void Grabber::XiDevice::grab_button(ButtonInfo &bi, bool grab) {
Expand Down
2 changes: 1 addition & 1 deletion grabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class Grabber {
class GrabFailedException : public std::exception {
char *msg;
public:
GrabFailedException(int code) { if (asprintf(&msg, "Grab Failed: %d", code) == -1) msg = NULL; }
GrabFailedException(int code) { if (asprintf(&msg, "Grab Failed: %d", code) == -1) msg = nullptr; }
virtual const char* what() const throw() { return msg ? msg : "Grab Failed"; }
~GrabFailedException() throw() { free(msg); }
};
Expand Down
42 changes: 21 additions & 21 deletions handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <X11/XKBlib.h>
#include <X11/Xproto.h>

XState *xstate = NULL;
XState *xstate = nullptr;

extern Window get_app_window(Window w);
extern Source<Window> current_app_window;
Expand Down Expand Up @@ -143,7 +143,7 @@ Window XState::get_window(Window w, Atom prop) {
Atom actual_type;
int actual_format;
unsigned long nitems, bytes_after;
unsigned char *prop_return = NULL;
unsigned char *prop_return = nullptr;

if (XGetWindowProperty(dpy, w, prop, 0, sizeof(Atom), False, XA_WINDOW, &actual_type, &actual_format,
&nitems, &bytes_after, &prop_return) != Success)
Expand All @@ -159,7 +159,7 @@ Atom XState::get_atom(Window w, Atom prop) {
Atom actual_type;
int actual_format;
unsigned long nitems, bytes_after;
unsigned char *prop_return = NULL;
unsigned char *prop_return = nullptr;

if (XGetWindowProperty(dpy, w, prop, 0, sizeof(Atom), False, XA_ATOM, &actual_type, &actual_format,
&nitems, &bytes_after, &prop_return) != Success)
Expand All @@ -175,7 +175,7 @@ bool XState::has_atom(Window w, Atom prop, Atom value) {
Atom actual_type;
int actual_format;
unsigned long nitems, bytes_after;
unsigned char *prop_return = NULL;
unsigned char *prop_return = nullptr;

if (XGetWindowProperty(dpy, w, prop, 0, sizeof(Atom), False, XA_ATOM, &actual_type, &actual_format,
&nitems, &bytes_after, &prop_return) != Success)
Expand Down Expand Up @@ -404,15 +404,15 @@ class IgnoreHandler : public Handler {
if (xstate->current_dev->master)
XTestFakeMotionEvent(dpy, DefaultScreen(dpy), e->x, e->y, 0);
if (proximity && !xstate->in_proximity)
parent->replace_child(NULL);
parent->replace_child(nullptr);
}
virtual void release(guint b, RTriple e) {
if (xstate->current_dev->master) {
XTestFakeMotionEvent(dpy, DefaultScreen(dpy), e->x, e->y, 0);
XTestFakeButtonEvent(dpy, b, false, CurrentTime);
}
if (proximity ? !xstate->in_proximity : !xstate->xinput_pressed.size())
parent->replace_child(NULL);
parent->replace_child(nullptr);
}
virtual std::string name() { return "Ignore"; }
virtual Grabber::State grab_mode() { return Grabber::NONE; }
Expand Down Expand Up @@ -443,7 +443,7 @@ class ButtonHandler : public Handler {
if (xstate->current_dev->master)
XTestFakeMotionEvent(dpy, DefaultScreen(dpy), e->x, e->y, 0);
if (proximity && !xstate->in_proximity)
parent->replace_child(NULL);
parent->replace_child(nullptr);
}
virtual void release(guint b, RTriple e) {
if (xstate->current_dev->master) {
Expand All @@ -453,14 +453,14 @@ class ButtonHandler : public Handler {
XTestFakeButtonEvent(dpy, b, false, CurrentTime);
}
if (proximity ? !xstate->in_proximity : !xstate->xinput_pressed.size())
parent->replace_child(NULL);
parent->replace_child(nullptr);
}
virtual std::string name() { return "Button"; }
virtual Grabber::State grab_mode() { return Grabber::NONE; }
};

void XState::bail_out() {
handler->replace_child(NULL);
handler->replace_child(nullptr);
xinput_pressed.clear();
XFlush(dpy);
}
Expand Down Expand Up @@ -513,7 +513,7 @@ void XState::ping() {

void XState::remove_device(int deviceid) {
if (current_dev && current_dev->dev == deviceid)
current_dev = NULL;
current_dev = nullptr;
}

void XState::ungrab(int deviceid) {
Expand All @@ -528,7 +528,7 @@ class WaitForPongHandler : public Handler, protected Timeout {
printf("Warning: %s timed out\n", "WaitForPongHandler");
xstate->bail_out();
}
virtual void pong() { parent->replace_child(NULL); }
virtual void pong() { parent->replace_child(nullptr); }
virtual std::string name() { return "WaitForPong"; }
virtual Grabber::State grab_mode() { return parent->grab_mode(); }
};
Expand All @@ -544,7 +544,7 @@ class AbstractScrollHandler : public Handler {
int orig_x, orig_y;

protected:
AbstractScrollHandler() : last_t(0), offset_x(0.0), offset_y(0.0) {
AbstractScrollHandler() : have_x(false), have_y(false), last_x(0.0), last_y(0.0), last_t(0), offset_x(0.0), offset_y(0.0) {
if (!prefs.move_back.get() || (xstate->current_dev && xstate->current_dev->absolute))
return;
Window dummy1, dummy2;
Expand Down Expand Up @@ -633,7 +633,7 @@ class ScrollHandler : public AbstractScrollHandler {
}
virtual void raw_motion(RTriple e, bool abs_x, bool abs_y) {
if (proximity && !xstate->in_proximity) {
parent->replace_child(NULL);
parent->replace_child(nullptr);
move_back();
}
if (xstate->xinput_pressed.size())
Expand Down Expand Up @@ -663,13 +663,13 @@ class ScrollAdvancedHandler : public AbstractScrollHandler {
}
virtual void release(guint b, RTriple e) {
Handler *p = parent;
p->replace_child(NULL);
p->replace_child(nullptr);
p->release(b, e);
move_back();
}
virtual void press(guint b, RTriple e) {
Handler *p = parent;
p->replace_child(NULL);
p->replace_child(nullptr);
p->press(b, e);
move_back();
}
Expand All @@ -691,7 +691,7 @@ class AdvancedStrokeActionHandler : public Handler {
if (stroke_action)
(*stroke_action)(s);
if (xstate->xinput_pressed.size() == 0)
parent->replace_child(NULL);
parent->replace_child(nullptr);
}
virtual std::string name() { return "InstantStrokeAction"; }
virtual Grabber::State grab_mode() { return Grabber::NONE; }
Expand Down Expand Up @@ -821,7 +821,7 @@ class AdvancedHandler : public Handler {
mods.clear();
xstate->fake_click(b);
}
return parent->replace_child(NULL);
return parent->replace_child(nullptr);
}
replay_button = 0;
mods.erase((b == button1) ? button2 : b);
Expand Down Expand Up @@ -975,15 +975,15 @@ class StrokeHandler : public Handler, public sigc::trackable {

if (stroke_action) {
(*stroke_action)(s);
return parent->replace_child(NULL);
return parent->replace_child(nullptr);
}
RRanking ranking;
RAction act = actions.get_action_list(grabber->current_class->get())->handle(s, ranking);
if (!IS_CLICK(act))
Ranking::queue_show(ranking, e);
if (!act) {
XkbBell(dpy, None, 0, None);
return parent->replace_child(NULL);
return parent->replace_child(nullptr);
}
RModifiers mods = act->prepare();
if (IS_CLICK(act))
Expand All @@ -1008,7 +1008,7 @@ class StrokeHandler : public Handler, public sigc::trackable {
unsetenv("EASYSTROKE_Y1");
unsetenv("EASYSTROKE_X2");
unsetenv("EASYSTROKE_Y2");
parent->replace_child(NULL);
parent->replace_child(nullptr);
}
public:
StrokeHandler(guint b, RTriple e) :
Expand Down Expand Up @@ -1098,7 +1098,7 @@ std::string XState::select_window() {
return grabber->current_class->get();
}

XState::XState() : current_dev(NULL), in_proximity(false), accepted(true) {
XState::XState() : current_dev(nullptr), in_proximity(false), accepted(true), modifiers(0) {
int n, opcode, event, error;
char **ext = XListExtensions(dpy, &n);
for (int i = 0; i < n; i++)
Expand Down
4 changes: 2 additions & 2 deletions handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class XState {
bool accepted;
std::set<guint> xinput_pressed;
guint modifiers;
std::map<guint, guint> core_inv_map;
std::map<guint, guint> core_inv_map;
private:
Window ping_window;
Handler *handler;
Expand All @@ -76,7 +76,7 @@ class Handler {
public:
Handler *child;
Handler *parent;
Handler() : child(NULL), parent(NULL) {}
Handler() : child(nullptr), parent(nullptr) {}
Handler *top() {
if (child)
return child->top();
Expand Down
Loading

0 comments on commit 30a879f

Please sign in to comment.