Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor adaptions to C++11 #74

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ SUBDIRS = \
calibrator \
gui

AM_CXXFLAGS = -Wall -ansi -pedantic
AM_CXXFLAGS = -Wall -std=c++11 -pedantic

bin_PROGRAMS = xinput_calibrator tester

Expand Down
12 changes: 6 additions & 6 deletions src/calibrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ const char* Calibrator::get_sysfs_name()

// TODO: more mechanisms

return NULL;
return nullptr;
}

bool Calibrator::is_sysfs_name(const char* name) {
DIR* dp = opendir(SYSFS_INPUT);
if (dp == NULL)
if (dp == nullptr)
return false;

while (dirent* ep = readdir(dp)) {
Expand Down Expand Up @@ -242,10 +242,10 @@ bool Calibrator::has_xorgconfd_support(Display* dpy) {
bool has_support = false;

Display* display = dpy;
if (dpy == NULL) // no connection to reuse
display = XOpenDisplay(NULL);
if (dpy == nullptr) // no connection to reuse
display = XOpenDisplay(nullptr);

if (display == NULL) {
if (display == nullptr) {
fprintf(stderr, "Unable to connect to X server\n");
exit(1);
}
Expand All @@ -255,7 +255,7 @@ bool Calibrator::has_xorgconfd_support(Display* dpy) {
has_support = true;
}

if (dpy == NULL) // no connection to reuse
if (dpy == nullptr) // no connection to reuse
XCloseDisplay(display);

return has_support;
Expand Down
39 changes: 19 additions & 20 deletions src/calibrator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@

#include <stdexcept>
#include <X11/Xlib.h>
#include <stdio.h>
#include <vector>

// XXX: we currently don't handle lines that are longer than this
#define MAX_LINE_LEN 1024
constexpr int max_line_len = 1024;

int xf86ScaleAxis(int Cx, int to_max, int to_min, int from_max, int from_min);
float scaleAxis(float Cx, int to_max, int to_min, int from_max, int from_min);
Expand Down Expand Up @@ -62,14 +61,14 @@ float scaleAxis(float Cx, int to_max, int to_min, int from_max, int from_min);
* | | | | | | | | |
* +--+--+--+--+--+--+--+--+
*/
const int num_blocks = 8;
constexpr int num_blocks = 8;

struct AxisInfo {
int min, max;
bool invert;
int min = -1, max = -1;
bool invert = false;

AxisInfo() : min(-1), max(-1), invert(false) { }
AxisInfo(int mi, int ma, bool inv = false) :
AxisInfo() { }
constexpr AxisInfo(int mi, int ma, bool inv = false) :
min(mi), max(ma), invert(inv) { }
AxisInfo(const AxisInfo& old) :
min(old.min), max(old.max), invert(old.invert) { }
Expand All @@ -82,13 +81,13 @@ struct AxisInfo {
/// struct to hold min/max info of the X and Y axis
struct XYinfo {
/// Axis swapped
bool swap_xy;
bool swap_xy = false;
/// X, Y axis
AxisInfo x, y;

XYinfo() : swap_xy(false) {}
XYinfo() {}

XYinfo(int xmi, int xma, int ymi, int yma, bool swap_xy_ = false,
constexpr XYinfo(int xmi, int xma, int ymi, int yma, bool swap_xy_ = false,
bool inv_x = false, bool inv_y = false) :
swap_xy(swap_xy_), x(xmi, xma, inv_x), y(ymi, yma, inv_y) {}

Expand All @@ -102,7 +101,7 @@ struct XYinfo {
y.max = xf86ScaleAxis(y.max, to.y.max, to.y.min, from.y.max, from.y.min);
}

void print(const char* xtra="\n") {
void print(const char* xtra="\n") const {
printf("XYinfo: x.min=%i, x.max=%i, y.min=%i, y.max=%i, swap_xy=%i, invert_x=%i, invert_y=%i%s",
x.min, x.max, y.min, y.max, swap_xy, x.invert, y.invert, xtra);
}
Expand Down Expand Up @@ -147,9 +146,9 @@ public:
const int thr_misclick=0,
const int thr_doubleclick=0,
const OutputType output_type=OUTYPE_AUTO,
const char* geometry=0,
const char* geometry=nullptr,
const bool use_timeout=1,
const char* output_filename = 0);
const char* output_filename=nullptr);

virtual ~Calibrator() {}

Expand Down Expand Up @@ -199,7 +198,7 @@ protected:
bool is_sysfs_name(const char* name);

/// Check whether the X server has xorg.conf.d support
bool has_xorgconfd_support(Display* display=NULL);
bool has_xorgconfd_support(Display* display=nullptr);

static int find_device(const char* pre_device, bool list_devices,
XID& device_id, const char*& device_name, XYinfo& device_axys);
Expand All @@ -224,23 +223,23 @@ protected:

// Threshold to keep the same point from being clicked twice.
// Set to zero if you don't want this check
int threshold_doubleclick;
int threshold_doubleclick = 0;

// Threshold to detect mis-clicks (clicks not along axes)
// A lower value forces more precise calibration
// Set to zero if you don't want this check
int threshold_misclick;
int threshold_misclick = 0;

// Type of output
OutputType output_type;
OutputType output_type = OUTYPE_AUTO;

// manually specified geometry string
const char* geometry;
const char* geometry = nullptr;

const bool use_timeout;
const bool use_timeout = 1;

// manually specified output filename
const char* output_filename;
const char* output_filename = nullptr;

// sysfs path/file
static const char* SYSFS_INPUT;
Expand Down
36 changes: 18 additions & 18 deletions src/calibrator/Evdev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ CalibratorEvdev::CalibratorEvdev(const char* const device_name0,
: Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, use_timeout, output_filename)
{
// init
display = XOpenDisplay(NULL);
if (display == NULL) {
display = XOpenDisplay(nullptr);
if (display == nullptr) {
throw WrongCalibratorException("Evdev: Unable to connect to X server");
}

Expand Down Expand Up @@ -393,7 +393,7 @@ XDeviceInfo* CalibratorEvdev::xinput_find_device_info(
Display *display, const char *name, Bool only_extended)
{
XDeviceInfo *devices;
XDeviceInfo *found = NULL;
XDeviceInfo *found = nullptr;
int loop;
int num_devices;
int len = strlen(name);
Expand Down Expand Up @@ -422,7 +422,7 @@ Display *display, const char *name, Bool only_extended)
"Warning: There are multiple devices named \"%s\".\n"
"To ensure the correct one is selected, please use "
"the device ID instead.\n\n", name);
return NULL;
return nullptr;
} else {
found = &devices[loop];
}
Expand Down Expand Up @@ -513,17 +513,17 @@ bool CalibratorEvdev::xinput_do_set_int_prop( const char * name,
bool CalibratorEvdev::output_xorgconfd(const XYinfo new_axys)
{
const char* sysfs_name = get_sysfs_name();
bool not_sysfs_name = (sysfs_name == NULL);
bool not_sysfs_name = (sysfs_name == nullptr);
if (not_sysfs_name)
sysfs_name = "!!Name_Of_TouchScreen!!";

if(output_filename == NULL || not_sysfs_name)
if(output_filename == nullptr || not_sysfs_name)
printf(" copy the snippet below into '/etc/X11/xorg.conf.d/99-calibration.conf' (/usr/share/X11/xorg.conf.d/ in some distro's)\n");
else
printf(" writing xorg.conf calibration data to '%s'\n", output_filename);

// xorg.conf.d snippet
char line[MAX_LINE_LEN];
char line[max_line_len];
std::string outstr;

outstr += "Section \"InputClass\"\n";
Expand All @@ -542,9 +542,9 @@ bool CalibratorEvdev::output_xorgconfd(const XYinfo new_axys)
if (not_sysfs_name)
printf("\nChange '%s' to your device's name in the snippet above.\n", sysfs_name);
// file out
else if(output_filename != NULL) {
else if(output_filename != nullptr) {
FILE* fid = fopen(output_filename, "w");
if (fid == NULL) {
if (fid == nullptr) {
fprintf(stderr, "Error: Can't open '%s' for writing. Make sure you have the necessary rights\n", output_filename);
fprintf(stderr, "New calibration data NOT saved\n");
return false;
Expand All @@ -559,17 +559,17 @@ bool CalibratorEvdev::output_xorgconfd(const XYinfo new_axys)
bool CalibratorEvdev::output_hal(const XYinfo new_axys)
{
const char* sysfs_name = get_sysfs_name();
bool not_sysfs_name = (sysfs_name == NULL);
bool not_sysfs_name = (sysfs_name == nullptr);
if (not_sysfs_name)
sysfs_name = "!!Name_Of_TouchScreen!!";

if(output_filename == NULL || not_sysfs_name)
if(output_filename == nullptr || not_sysfs_name)
printf(" copy the policy below into '/etc/hal/fdi/policy/touchscreen.fdi'\n");
else
printf(" writing HAL calibration data to '%s'\n", output_filename);

// HAL policy output
char line[MAX_LINE_LEN];
char line[max_line_len];
std::string outstr;

sprintf(line, "<match key=\"info.product\" contains=\"%s\">\n", sysfs_name);
Expand All @@ -585,9 +585,9 @@ bool CalibratorEvdev::output_hal(const XYinfo new_axys)
if (not_sysfs_name)
printf("\nChange '%s' to your device's name in the config above.\n", sysfs_name);
// file out
else if(output_filename != NULL) {
else if(output_filename != nullptr) {
FILE* fid = fopen(output_filename, "w");
if (fid == NULL) {
if (fid == nullptr) {
fprintf(stderr, "Error: Can't open '%s' for writing. Make sure you have the necessary rights\n", output_filename);
fprintf(stderr, "New calibration data NOT saved\n");
return false;
Expand All @@ -601,13 +601,13 @@ bool CalibratorEvdev::output_hal(const XYinfo new_axys)

bool CalibratorEvdev::output_xinput(const XYinfo new_axys)
{
if(output_filename == NULL)
if(output_filename == nullptr)
printf(" Install the 'xinput' tool and copy the command(s) below in a script that starts with your X session\n");
else
printf(" writing calibration script to '%s'\n", output_filename);

// create startup script
char line[MAX_LINE_LEN];
char line[max_line_len];
std::string outstr;

sprintf(line, " xinput set-int-prop \"%s\" \"Evdev Axis Calibration\" 32 %d %d %d %d\n", device_name, new_axys.x.min, new_axys.x.max, new_axys.y.min, new_axys.y.max);
Expand All @@ -618,9 +618,9 @@ bool CalibratorEvdev::output_xinput(const XYinfo new_axys)
// console out
printf("%s", outstr.c_str());
// file out
if(output_filename != NULL) {
if(output_filename != nullptr) {
FILE* fid = fopen(output_filename, "w");
if (fid == NULL) {
if (fid == nullptr) {
fprintf(stderr, "Error: Can't open '%s' for writing. Make sure you have the necessary rights\n", output_filename);
fprintf(stderr, "New calibration data NOT saved\n");
return false;
Expand Down
18 changes: 9 additions & 9 deletions src/calibrator/Evdev.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
class CalibratorEvdev: public Calibrator
{
private:
Display *display;
XDeviceInfo *devInfo;
XDevice *dev;
Display *display = nullptr;
XDeviceInfo *devInfo = nullptr;
XDevice *dev = nullptr;

protected:
// protected constructor: should only be used by subclasses!
Expand All @@ -46,9 +46,9 @@ class CalibratorEvdev: public Calibrator
const int thr_misclick=0,
const int thr_doubleclick=0,
const OutputType output_type=OUTYPE_AUTO,
const char* geometry=0,
const char* geometry=nullptr,
const bool use_timeout=false,
const char* output_filename = 0);
const char* output_filename=nullptr);

public:
CalibratorEvdev(const char* const device_name,
Expand All @@ -57,14 +57,14 @@ class CalibratorEvdev: public Calibrator
const int thr_misclick=0,
const int thr_doubleclick=0,
const OutputType output_type=OUTYPE_AUTO,
const char* geometry=0,
const char* geometry=nullptr,
const bool use_timeout=false,
const char* output_filename = 0);
const char* output_filename=nullptr);
virtual ~CalibratorEvdev();

/// calculate and apply the calibration
virtual bool finish(int width, int height);
virtual bool finish_data(const XYinfo &new_axys);
bool finish(int width, int height) override;
bool finish_data(const XYinfo &new_axys) override;

bool set_swapxy(const int swap_xy);
bool set_invert_xy(const int invert_x, const int invert_y);
Expand Down
13 changes: 7 additions & 6 deletions src/calibrator/EvdevTester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,23 @@ class CalibratorEvdevTester: public CalibratorTesterInterface, public Calibrator
public:
CalibratorEvdevTester(const char* const device_name, const XYinfo& axys,
const int thr_misclick=0, const int thr_doubleclick=0,
const OutputType output_type=OUTYPE_AUTO, const char* geometry=0);
const OutputType output_type=OUTYPE_AUTO, const char* geometry=nullptr);

virtual bool finish_data(const XYinfo &new_axis);
bool finish_data(const XYinfo &new_axis) override final;

// emulate the driver processing the coordinates in 'raw'
virtual XYinfo emulate_driver(const XYinfo& raw, bool useNewAxis, const XYinfo& screen, const XYinfo& device);
XYinfo emulate_driver(const XYinfo& raw, bool useNewAxis,
const XYinfo& screen, const XYinfo& device) override final;

virtual void new_axis_print() {
void new_axis_print() override final {
new_axis.print();
}

//* From CalibratorEvdev
virtual bool add_click(int x, int y) {
bool add_click(int x, int y) override final {
return CalibratorEvdev::add_click(x, y);
}
virtual bool finish(int width, int height) {
bool finish(int width, int height) override final {
return CalibratorEvdev::finish(width, height);
}

Expand Down
16 changes: 7 additions & 9 deletions src/calibrator/Tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,23 @@ class CalibratorTester: public CalibratorTesterInterface, public Calibrator
public:
CalibratorTester(const char* const device_name, const XYinfo& axys,
const int thr_misclick=0, const int thr_doubleclick=0,
const OutputType output_type=OUTYPE_AUTO, const char* geometry=0);
const OutputType output_type=OUTYPE_AUTO, const char* geometry=nullptr);

virtual bool finish_data(const XYinfo &new_axis);
bool finish_data(const XYinfo &new_axis) override final;

// emulate the driver processing the coordinates in 'raw'
virtual XYinfo emulate_driver(const XYinfo& raw,
bool useNewAxis,
const XYinfo& screen,
const XYinfo& device);
XYinfo emulate_driver(const XYinfo& raw, bool useNewAxis,
const XYinfo& screen, const XYinfo& device) override final;

virtual void new_axis_print() {
void new_axis_print() override final {
new_axis.print();
}

//* From Calibrator
virtual bool add_click(int x, int y) {
bool add_click(int x, int y) override final {
return Calibrator::add_click(x, y);
}
virtual bool finish(int width, int height) {
bool finish(int width, int height) override final {
return Calibrator::finish(width, height);
}
};
Expand Down
Loading