diff --git a/.gitignore b/.gitignore index 4362eda2..30aa8b7f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ po/??_?? po/POTFILES.in po/*.pot easystroke.desktop +.clang_complete diff --git a/Makefile b/Makefile index 33b02adf..71beaa42 100644 --- a/Makefile +++ b/Makefile @@ -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` @@ -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 @@ -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) >> $@;) diff --git a/actiondb.cc b/actiondb.cc index 236d580c..6b35f47c 100644 --- a/actiondb.cc +++ b/actiondb.cc @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -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()); @@ -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 void ActionListDiff::serialize(Archive & ar, const unsigned int version) { ar & deleted; diff --git a/actions.cc b/actions.cc index e9544f06..45c03761 100644 --- a/actions.cc +++ b/actions.cc @@ -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); @@ -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; @@ -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; } @@ -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 sel = parent->tv.get_selection(); @@ -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(sigc::mem_fun(ps, &OnStroke::delayed_run))); diff --git a/gesture.cc b/gesture.cc index 6b670dc8..8531c084 100644 --- a/gesture.cc +++ b/gesture.cc @@ -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); diff --git a/grabber.cc b/grabber.cc index 899c282c..3e8512f0 100644 --- a/grabber.cc +++ b/grabber.cc @@ -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; @@ -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) { diff --git a/grabber.h b/grabber.h index 9b843af4..70ddd3c5 100644 --- a/grabber.h +++ b/grabber.h @@ -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); } }; diff --git a/handler.cc b/handler.cc index 9d950758..8830ea28 100644 --- a/handler.cc +++ b/handler.cc @@ -24,7 +24,7 @@ #include #include -XState *xstate = NULL; +XState *xstate = nullptr; extern Window get_app_window(Window w); extern Source current_app_window; @@ -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) @@ -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) @@ -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) @@ -404,7 +404,7 @@ 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) { @@ -412,7 +412,7 @@ class IgnoreHandler : 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 "Ignore"; } virtual Grabber::State grab_mode() { return Grabber::NONE; } @@ -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) { @@ -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); } @@ -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) { @@ -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(); } }; @@ -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; @@ -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()) @@ -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(); } @@ -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; } @@ -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); @@ -975,7 +975,7 @@ 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); @@ -983,7 +983,7 @@ class StrokeHandler : public Handler, public sigc::trackable { 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)) @@ -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) : @@ -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++) diff --git a/handler.h b/handler.h index ca27de97..a59f321f 100644 --- a/handler.h +++ b/handler.h @@ -59,7 +59,7 @@ class XState { bool accepted; std::set xinput_pressed; guint modifiers; - std::map core_inv_map; + std::map core_inv_map; private: Window ping_window; Handler *handler; @@ -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(); diff --git a/main.cc b/main.cc index 8cd9c561..af46e07d 100644 --- a/main.cc +++ b/main.cc @@ -42,11 +42,11 @@ extern Source disabled; bool experimental = false; int verbosity = 0; -const char *prefs_versions[] = { "-0.5.5", "-0.4.1", "-0.4.0", "", NULL }; -const char *actions_versions[] = { "-0.5.6", "-0.4.1", "-0.4.0", "", NULL }; +const char *prefs_versions[] = { "-0.5.5", "-0.4.1", "-0.4.0", "", nullptr }; +const char *actions_versions[] = { "-0.5.6", "-0.4.1", "-0.4.0", "", nullptr }; Source current_app_window(None); std::string config_dir; -Win *win = NULL; +Win *win = nullptr; Display *dpy; Window ROOT; @@ -172,7 +172,7 @@ void sig_int(int) { class App : public Gtk::Application, Base { public: App(int& argc, char**& argv, const Glib::ustring& application_id, Gio::ApplicationFlags flags=Gio::APPLICATION_FLAGS_NONE) : - Gtk::Application(argc, argv, application_id, flags), remote(false) {} + Gtk::Application(argc, argv, application_id, flags), remote(false), enabled(nullptr) {} ~App(); static void usage(const char *me); @@ -380,7 +380,7 @@ void App::on_activate() { signal(SIGINT, &sig_int); signal(SIGCHLD, SIG_IGN); - dpy = XOpenDisplay(NULL); + dpy = XOpenDisplay(nullptr); if (!dpy) { printf(_("Couldn't open display.\n")); exit(EXIT_FAILURE); @@ -400,7 +400,7 @@ void App::on_activate() { trace.reset(init_trace()); Glib::RefPtr screen = Gdk::Display::get_default()->get_default_screen(); - g_signal_connect(screen->gobj(), "composited-changed", &schedule_reload_trace, NULL); + g_signal_connect(screen->gobj(), "composited-changed", &schedule_reload_trace, nullptr); screen->signal_size_changed().connect(sigc::ptr_fun(&schedule_reload_trace)); Notifier *trace_notify = new Notifier(sigc::ptr_fun(&schedule_reload_trace)); prefs.trace.connect(trace_notify); @@ -462,7 +462,7 @@ void App::create_config_dir() { config_dir += "/.easystroke"; } struct stat st; - char *name = realpath(config_dir.c_str(), NULL); + char *name = realpath(config_dir.c_str(), nullptr); // check if the directory does not exist if (lstat(name, &st) == -1) { @@ -633,7 +633,7 @@ class Modifiers : Timeout { Glib::ustring str; OSD *osd; public: - Modifiers(guint mods_, Glib::ustring str_) : mods(mods_), str(str_), osd(NULL) { + Modifiers(guint mods_, Glib::ustring str_) : mods(mods_), str(str_), osd(nullptr) { if (prefs.show_osd.get()) set_timeout(150); all.insert(this); diff --git a/prefs.cc b/prefs.cc index ec592998..202973db 100644 --- a/prefs.cc +++ b/prefs.cc @@ -299,9 +299,9 @@ Prefs::Prefs() { CellRendererTextish *button_renderer = cell_renderer_textish_new (); button_renderer->mode = CELL_RENDERER_TEXTISH_MODE_Popup; - GtkTreeViewColumn *col_button = gtk_tree_view_column_new_with_attributes(_("Button"), GTK_CELL_RENDERER (button_renderer), "text", cols.button.index(), NULL); + GtkTreeViewColumn *col_button = gtk_tree_view_column_new_with_attributes(_("Button"), GTK_CELL_RENDERER (button_renderer), "text", cols.button.index(), nullptr); gtk_tree_view_append_column(tv->gobj(), col_button); - g_object_set(button_renderer, "editable", true, NULL); + g_object_set(button_renderer, "editable", true, nullptr); g_signal_connect(button_renderer, "editing-started", G_CALLBACK(on_prefs_editing_started), this); bbutton->signal_clicked().connect(sigc::mem_fun(*this, &Prefs::on_select_button)); diff --git a/shape.cc b/shape.cc index a6d4a617..15b64727 100644 --- a/shape.cc +++ b/shape.cc @@ -73,7 +73,7 @@ void Shape::timeout() { } void Shape::clear() { - XShapeCombineRectangles(dpy, win, ShapeBounding, 0, 0, NULL, 0, ShapeSet, YXBanded); + XShapeCombineRectangles(dpy, win, ShapeBounding, 0, 0, nullptr, 0, ShapeSet, YXBanded); } Shape::~Shape() { diff --git a/stats.cc b/stats.cc index 4402293e..97c894d3 100644 --- a/stats.cc +++ b/stats.cc @@ -280,7 +280,7 @@ void Stats::on_pdf() { printf("creating table took %ld us\n", (tv2.tv_sec - tv1.tv_sec)*1000000 + tv2.tv_usec - tv1.tv_usec); } if (!fork()) { - execlp("xdg-open", "xdg-open", "/tmp/strokes.pdf", NULL); + execlp("xdg-open", "xdg-open", "/tmp/strokes.pdf", nullptr); exit(EXIT_FAILURE); } } diff --git a/util.h b/util.h index 97dde2cf..d8f5e85b 100644 --- a/util.h +++ b/util.h @@ -19,11 +19,11 @@ #include class Timeout { - // Invariant: c == &connection || c == NULL + // Invariant: c == &connection || c == nullptr sigc::connection *c; sigc::connection connection; // We have to account for the possibilty that timeout() destroys the object - bool to() { c = NULL; timeout(); return false; } + bool to() { c = nullptr; timeout(); return false; } public: Timeout() : c(0) {} protected: diff --git a/var.h b/var.h index 84cde86f..3f2806c7 100644 --- a/var.h +++ b/var.h @@ -24,6 +24,7 @@ class Base { public: virtual void notify() = 0; + virtual ~Base() {} }; class Notifier : public Base { @@ -53,11 +54,13 @@ template class Out { public: void connect(Base *s) { out.insert(s); } virtual T get() const = 0; + virtual ~Out() {} }; template class In { public: virtual void set(const T x) = 0; + virtual ~In() {} }; template class IO : public In, public Out {}; diff --git a/win.cc b/win.cc index 4793f437..da41b0e8 100644 --- a/win.cc +++ b/win.cc @@ -220,7 +220,7 @@ void Win::show_hide_icon() { icon->signal_activate().connect(sigc::mem_fun(*this, &Win::show_hide)); icon->signal_popup_menu().connect(sigc::mem_fun(*this, &Win::show_popup)); if (gtk_major_version > 2 || (gtk_major_version == 2 && gtk_minor_version >= 15)) - g_signal_connect(icon->gobj(), "button-release-event", G_CALLBACK(icon_clicked), NULL); + g_signal_connect(icon->gobj(), "button-release-event", G_CALLBACK(icon_clicked), nullptr); } else { if (icon) icon.reset();