Skip to content

Commit 30a879f

Browse files
committed
Update to c++11
1 parent d14b274 commit 30a879f

File tree

16 files changed

+68
-55
lines changed

16 files changed

+68
-55
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ po/??_??
1111
po/POTFILES.in
1212
po/*.pot
1313
easystroke.desktop
14+
.clang_complete

Makefile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ LOCALEDIR= $(PREFIX)/share/locale
2121
DFLAGS =
2222
OFLAGS = -O2
2323
AOFLAGS = -O3
24-
STROKEFLAGS = -Wall -std=c99 $(DFLAGS)
25-
CXXFLAGS = -Wall $(DFLAGS) -DLOCALEDIR=\"$(LOCALEDIR)\" `pkg-config gtkmm-3.0 dbus-glib-1 --cflags`
26-
CFLAGS = -Wall $(DFLAGS) -DLOCALEDIR=\"$(LOCALEDIR)\" `pkg-config gtk+-3.0 --cflags` -DGETTEXT_PACKAGE='"easystroke"'
24+
STROKEFLAGS = -Wall -std=c11 $(DFLAGS)
25+
CXXSTD = -std=c++11
26+
INCLUDES = $(shell pkg-config gtkmm-3.0 dbus-glib-1 --cflags)
27+
CXXFLAGS = $(CXXSTD) -Wall $(DFLAGS) -DLOCALEDIR=\"$(LOCALEDIR)\" $(INCLUDES)
28+
CFLAGS = -std=c11 -Wall $(DFLAGS) -DLOCALEDIR=\"$(LOCALEDIR)\" $(INCLUDES) -DGETTEXT_PACKAGE='"easystroke"'
2729
LDFLAGS = $(DFLAGS)
2830

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

5254
all: $(BINARY) $(MOFILES)
5355

54-
.PHONY: all clean translate update-translations compile-translations
56+
.PHONY: all clean translate update-translations compile-translations complete
5557

5658
clean:
5759
$(RM) $(OFILES) $(BINARY) $(GENFILES) $(DEPFILES) $(MANPAGE) $(GZFILES) po/*.pot
@@ -146,3 +148,9 @@ tmp/$(DIST): $(GIT)
146148
$(DIST).tar.gz: tmp/$(DIST)
147149
tar -czf $@ -C tmp/ $(DIST)
148150
$(RM) -r tmp
151+
152+
complete: .clang_complete
153+
154+
.clang_complete: Makefile
155+
@echo $(CXXSTD) > $@
156+
@$(foreach inc,$(INCLUDES),echo $(inc) >> $@;)

actiondb.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <iostream>
2222
#include <fstream>
23+
#include <string>
2324
#include <boost/archive/text_oarchive.hpp>
2425
#include <boost/archive/text_iarchive.hpp>
2526
#include <boost/serialization/map.hpp>
@@ -121,7 +122,7 @@ void Command::run() {
121122
pid_t pid = fork();
122123
switch (pid) {
123124
case 0:
124-
execlp("/bin/sh", "sh", "-c", cmd.c_str(), NULL);
125+
execlp("/bin/sh", "sh", "-c", cmd.c_str(), nullptr);
125126
exit(1);
126127
case -1:
127128
printf(_("Error: can't execute command \"%s\": fork() failed\n"), cmd.c_str());
@@ -142,7 +143,7 @@ const Glib::ustring Button::get_label() const {
142143

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

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

147148
template<class Archive> void ActionListDiff::serialize(Archive & ar, const unsigned int version) {
148149
ar & deleted;

actions.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,12 @@ Actions::Actions() :
193193
int i = 0;
194194
while (Misc::types[i]) i++;
195195
CellRendererTextish *arg_renderer = cell_renderer_textish_new_with_items ((gchar**)Misc::types, i);
196-
GtkTreeViewColumn *col_arg = gtk_tree_view_column_new_with_attributes(_("Details"), GTK_CELL_RENDERER (arg_renderer), "text", cols.arg.index(), NULL);
196+
GtkTreeViewColumn *col_arg = gtk_tree_view_column_new_with_attributes(_("Details"), GTK_CELL_RENDERER (arg_renderer), "text", cols.arg.index(), nullptr);
197197
gtk_tree_view_append_column(tv.gobj(), col_arg);
198198

199-
gtk_tree_view_column_set_cell_data_func (col_arg, GTK_CELL_RENDERER (arg_renderer), on_actions_cell_data_arg, this, NULL);
199+
gtk_tree_view_column_set_cell_data_func (col_arg, GTK_CELL_RENDERER (arg_renderer), on_actions_cell_data_arg, this, nullptr);
200200
gtk_tree_view_column_set_resizable(col_arg, true);
201-
g_object_set(arg_renderer, "editable", true, NULL);
201+
g_object_set(arg_renderer, "editable", true, nullptr);
202202
g_signal_connect(arg_renderer, "key-edited", G_CALLBACK(on_actions_accel_edited), this);
203203
g_signal_connect(arg_renderer, "combo-edited", G_CALLBACK(on_actions_combo_edited), this);
204204
g_signal_connect(arg_renderer, "edited", G_CALLBACK(on_actions_text_edited), this);
@@ -262,7 +262,7 @@ void Actions::on_cell_data_arg(GtkCellRenderer *cell, gchar *path) {
262262
Gtk::TreeModel::iterator iter = tm->get_iter(path);
263263
bool bold = (*iter)[cols.action_bold];
264264
bool deactivated = (*iter)[cols.deactivated];
265-
g_object_set(cell, "sensitive", !deactivated, "weight", bold ? 700 : 400, NULL);
265+
g_object_set(cell, "sensitive", !deactivated, "weight", bold ? 700 : 400, nullptr);
266266
CellRendererTextish *renderer = CELL_RENDERER_TEXTISH (cell);
267267
if (!renderer)
268268
return;
@@ -309,7 +309,7 @@ bool Actions::AppsStore::row_drop_possible_vfunc(const Gtk::TreeModel::Path &des
309309
if (model != parent->tm)
310310
return false;
311311
Gtk::TreeIter dest_iter = parent->apps_model->get_iter(dest);
312-
ActionListDiff *actions = dest_iter ? (*dest_iter)[parent->ca.actions] : (ActionListDiff *)NULL;
312+
ActionListDiff *actions = dest_iter ? (*dest_iter)[parent->ca.actions] : (ActionListDiff *)nullptr;
313313
return actions && actions != parent->action_list;
314314
}
315315

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

757757
OnStroke ps(this, dialog, row);
758758
stroke_action.reset(new sigc::slot<void, RStroke>(sigc::mem_fun(ps, &OnStroke::delayed_run)));

gesture.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ int Stroke::compare(RStroke a, RStroke b, double &score) {
9999
}
100100
return -1;
101101
}
102-
double cost = stroke_compare(a->stroke.get(), b->stroke.get(), NULL, NULL);
102+
double cost = stroke_compare(a->stroke.get(), b->stroke.get(), nullptr, nullptr);
103103
if (cost >= stroke_infinity)
104104
return -1;
105105
score = MAX(1.0 - 2.5*cost, 0.0);

grabber.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ void Grabber::new_device(XIDeviceInfo *info) {
367367
}
368368
}
369369

370-
Grabber::XiDevice::XiDevice(Grabber *parent, XIDeviceInfo *info) : absolute(false), proximity_axis(-1), scale_x(1.0), scale_y(1.0), num_buttons(0) {
370+
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) {
371371
static XAtom PROXIMITY(AXIS_LABEL_PROP_ABS_DISTANCE);
372372
dev = info->deviceid;
373373
name = info->name;
@@ -398,7 +398,7 @@ Grabber::XiDevice::XiDevice(Grabber *parent, XIDeviceInfo *info) : absolute(fals
398398

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

404404
void Grabber::XiDevice::grab_button(ButtonInfo &bi, bool grab) {

grabber.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class Grabber {
123123
class GrabFailedException : public std::exception {
124124
char *msg;
125125
public:
126-
GrabFailedException(int code) { if (asprintf(&msg, "Grab Failed: %d", code) == -1) msg = NULL; }
126+
GrabFailedException(int code) { if (asprintf(&msg, "Grab Failed: %d", code) == -1) msg = nullptr; }
127127
virtual const char* what() const throw() { return msg ? msg : "Grab Failed"; }
128128
~GrabFailedException() throw() { free(msg); }
129129
};

handler.cc

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include <X11/XKBlib.h>
2525
#include <X11/Xproto.h>
2626

27-
XState *xstate = NULL;
27+
XState *xstate = nullptr;
2828

2929
extern Window get_app_window(Window w);
3030
extern Source<Window> current_app_window;
@@ -143,7 +143,7 @@ Window XState::get_window(Window w, Atom prop) {
143143
Atom actual_type;
144144
int actual_format;
145145
unsigned long nitems, bytes_after;
146-
unsigned char *prop_return = NULL;
146+
unsigned char *prop_return = nullptr;
147147

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

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

180180
if (XGetWindowProperty(dpy, w, prop, 0, sizeof(Atom), False, XA_ATOM, &actual_type, &actual_format,
181181
&nitems, &bytes_after, &prop_return) != Success)
@@ -404,15 +404,15 @@ class IgnoreHandler : public Handler {
404404
if (xstate->current_dev->master)
405405
XTestFakeMotionEvent(dpy, DefaultScreen(dpy), e->x, e->y, 0);
406406
if (proximity && !xstate->in_proximity)
407-
parent->replace_child(NULL);
407+
parent->replace_child(nullptr);
408408
}
409409
virtual void release(guint b, RTriple e) {
410410
if (xstate->current_dev->master) {
411411
XTestFakeMotionEvent(dpy, DefaultScreen(dpy), e->x, e->y, 0);
412412
XTestFakeButtonEvent(dpy, b, false, CurrentTime);
413413
}
414414
if (proximity ? !xstate->in_proximity : !xstate->xinput_pressed.size())
415-
parent->replace_child(NULL);
415+
parent->replace_child(nullptr);
416416
}
417417
virtual std::string name() { return "Ignore"; }
418418
virtual Grabber::State grab_mode() { return Grabber::NONE; }
@@ -443,7 +443,7 @@ class ButtonHandler : public Handler {
443443
if (xstate->current_dev->master)
444444
XTestFakeMotionEvent(dpy, DefaultScreen(dpy), e->x, e->y, 0);
445445
if (proximity && !xstate->in_proximity)
446-
parent->replace_child(NULL);
446+
parent->replace_child(nullptr);
447447
}
448448
virtual void release(guint b, RTriple e) {
449449
if (xstate->current_dev->master) {
@@ -453,14 +453,14 @@ class ButtonHandler : public Handler {
453453
XTestFakeButtonEvent(dpy, b, false, CurrentTime);
454454
}
455455
if (proximity ? !xstate->in_proximity : !xstate->xinput_pressed.size())
456-
parent->replace_child(NULL);
456+
parent->replace_child(nullptr);
457457
}
458458
virtual std::string name() { return "Button"; }
459459
virtual Grabber::State grab_mode() { return Grabber::NONE; }
460460
};
461461

462462
void XState::bail_out() {
463-
handler->replace_child(NULL);
463+
handler->replace_child(nullptr);
464464
xinput_pressed.clear();
465465
XFlush(dpy);
466466
}
@@ -513,7 +513,7 @@ void XState::ping() {
513513

514514
void XState::remove_device(int deviceid) {
515515
if (current_dev && current_dev->dev == deviceid)
516-
current_dev = NULL;
516+
current_dev = nullptr;
517517
}
518518

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

546546
protected:
547-
AbstractScrollHandler() : last_t(0), offset_x(0.0), offset_y(0.0) {
547+
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) {
548548
if (!prefs.move_back.get() || (xstate->current_dev && xstate->current_dev->absolute))
549549
return;
550550
Window dummy1, dummy2;
@@ -633,7 +633,7 @@ class ScrollHandler : public AbstractScrollHandler {
633633
}
634634
virtual void raw_motion(RTriple e, bool abs_x, bool abs_y) {
635635
if (proximity && !xstate->in_proximity) {
636-
parent->replace_child(NULL);
636+
parent->replace_child(nullptr);
637637
move_back();
638638
}
639639
if (xstate->xinput_pressed.size())
@@ -663,13 +663,13 @@ class ScrollAdvancedHandler : public AbstractScrollHandler {
663663
}
664664
virtual void release(guint b, RTriple e) {
665665
Handler *p = parent;
666-
p->replace_child(NULL);
666+
p->replace_child(nullptr);
667667
p->release(b, e);
668668
move_back();
669669
}
670670
virtual void press(guint b, RTriple e) {
671671
Handler *p = parent;
672-
p->replace_child(NULL);
672+
p->replace_child(nullptr);
673673
p->press(b, e);
674674
move_back();
675675
}
@@ -691,7 +691,7 @@ class AdvancedStrokeActionHandler : public Handler {
691691
if (stroke_action)
692692
(*stroke_action)(s);
693693
if (xstate->xinput_pressed.size() == 0)
694-
parent->replace_child(NULL);
694+
parent->replace_child(nullptr);
695695
}
696696
virtual std::string name() { return "InstantStrokeAction"; }
697697
virtual Grabber::State grab_mode() { return Grabber::NONE; }
@@ -821,7 +821,7 @@ class AdvancedHandler : public Handler {
821821
mods.clear();
822822
xstate->fake_click(b);
823823
}
824-
return parent->replace_child(NULL);
824+
return parent->replace_child(nullptr);
825825
}
826826
replay_button = 0;
827827
mods.erase((b == button1) ? button2 : b);
@@ -975,15 +975,15 @@ class StrokeHandler : public Handler, public sigc::trackable {
975975

976976
if (stroke_action) {
977977
(*stroke_action)(s);
978-
return parent->replace_child(NULL);
978+
return parent->replace_child(nullptr);
979979
}
980980
RRanking ranking;
981981
RAction act = actions.get_action_list(grabber->current_class->get())->handle(s, ranking);
982982
if (!IS_CLICK(act))
983983
Ranking::queue_show(ranking, e);
984984
if (!act) {
985985
XkbBell(dpy, None, 0, None);
986-
return parent->replace_child(NULL);
986+
return parent->replace_child(nullptr);
987987
}
988988
RModifiers mods = act->prepare();
989989
if (IS_CLICK(act))
@@ -1008,7 +1008,7 @@ class StrokeHandler : public Handler, public sigc::trackable {
10081008
unsetenv("EASYSTROKE_Y1");
10091009
unsetenv("EASYSTROKE_X2");
10101010
unsetenv("EASYSTROKE_Y2");
1011-
parent->replace_child(NULL);
1011+
parent->replace_child(nullptr);
10121012
}
10131013
public:
10141014
StrokeHandler(guint b, RTriple e) :
@@ -1098,7 +1098,7 @@ std::string XState::select_window() {
10981098
return grabber->current_class->get();
10991099
}
11001100

1101-
XState::XState() : current_dev(NULL), in_proximity(false), accepted(true) {
1101+
XState::XState() : current_dev(nullptr), in_proximity(false), accepted(true), modifiers(0) {
11021102
int n, opcode, event, error;
11031103
char **ext = XListExtensions(dpy, &n);
11041104
for (int i = 0; i < n; i++)

handler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class XState {
5959
bool accepted;
6060
std::set<guint> xinput_pressed;
6161
guint modifiers;
62-
std::map<guint, guint> core_inv_map;
62+
std::map<guint, guint> core_inv_map;
6363
private:
6464
Window ping_window;
6565
Handler *handler;
@@ -76,7 +76,7 @@ class Handler {
7676
public:
7777
Handler *child;
7878
Handler *parent;
79-
Handler() : child(NULL), parent(NULL) {}
79+
Handler() : child(nullptr), parent(nullptr) {}
8080
Handler *top() {
8181
if (child)
8282
return child->top();

0 commit comments

Comments
 (0)