Remove unused files
This commit is contained in:
		@@ -1,256 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright 2019-2020 PixlOne
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation, either version 3 of the License, or
 | 
					 | 
				
			||||||
 * (at your option) any later version.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <unistd.h>
 | 
					 | 
				
			||||||
#include <future>
 | 
					 | 
				
			||||||
#include <hidpp20/Error.h>
 | 
					 | 
				
			||||||
#include <hidpp/SimpleDispatcher.h>
 | 
					 | 
				
			||||||
#include <hidpp20/IAdjustableDPI.h>
 | 
					 | 
				
			||||||
#include <hidpp20/ISmartShift.h>
 | 
					 | 
				
			||||||
#include <hidpp20/IHiresScroll.h>
 | 
					 | 
				
			||||||
#include <cmath>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "Actions.h"
 | 
					 | 
				
			||||||
#include "util.h"
 | 
					 | 
				
			||||||
#include "EvdevDevice.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
using namespace logid;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Gesture::Gesture(ButtonAction* ba, GestureMode m, void* aux) : action (ba), mode (m)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    switch(m)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        case GestureMode::OnFewPixels:
 | 
					 | 
				
			||||||
            per_pixel = *(int*)aux;
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        case GestureMode::Axis:
 | 
					 | 
				
			||||||
            axis = *(axis_info*)aux;
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        default:
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
NoAction* NoAction::copy(Device *dev)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    auto action = new NoAction();
 | 
					 | 
				
			||||||
    action->device = dev;
 | 
					 | 
				
			||||||
    return action;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
KeyAction* KeyAction::copy(Device *dev)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    auto action = new KeyAction(keys);
 | 
					 | 
				
			||||||
    action->device = dev;
 | 
					 | 
				
			||||||
    return action;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
GestureAction* GestureAction::copy(Device* dev)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    auto action = new GestureAction({});
 | 
					 | 
				
			||||||
    action->device = dev;
 | 
					 | 
				
			||||||
    for(auto it : gestures)
 | 
					 | 
				
			||||||
        action->gestures.insert({it.first, new Gesture(*it.second, dev)});
 | 
					 | 
				
			||||||
    return action;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
SmartshiftAction* SmartshiftAction::copy(Device* dev)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    auto action = new SmartshiftAction();
 | 
					 | 
				
			||||||
    action->device = dev;
 | 
					 | 
				
			||||||
    return action;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
HiresScrollAction* HiresScrollAction::copy(Device* dev)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    auto action = new HiresScrollAction();
 | 
					 | 
				
			||||||
    action->device = dev;
 | 
					 | 
				
			||||||
    return action;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
CycleDPIAction* CycleDPIAction::copy(Device* dev)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    auto action = new CycleDPIAction(dpis);
 | 
					 | 
				
			||||||
    action->device = dev;
 | 
					 | 
				
			||||||
    return action;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
ChangeDPIAction* ChangeDPIAction::copy(Device* dev)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    auto action = new ChangeDPIAction(dpi_inc);
 | 
					 | 
				
			||||||
    action->device = dev;
 | 
					 | 
				
			||||||
    return action;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void KeyAction::press()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    //KeyPress event for each in keys
 | 
					 | 
				
			||||||
    for(unsigned int i : keys)
 | 
					 | 
				
			||||||
        global_evdev->sendEvent(EV_KEY, i, 1);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void KeyAction::release()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    //KeyRelease event for each in keys
 | 
					 | 
				
			||||||
    for(unsigned int i : keys)
 | 
					 | 
				
			||||||
        global_evdev->sendEvent(EV_KEY, i, 0);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void GestureAction::press()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    for(auto g : gestures)
 | 
					 | 
				
			||||||
        g.second->per_pixel_mod = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    held = true;
 | 
					 | 
				
			||||||
    x = 0;
 | 
					 | 
				
			||||||
    y = 0;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void GestureAction::move(HIDPP20::IReprogControlsV4::Move m)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    x += m.x;
 | 
					 | 
				
			||||||
    y += m.y;
 | 
					 | 
				
			||||||
    if(m.y != 0 && abs(y) > 50)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        auto g = gestures.find(m.y > 0 ? Direction::Down : Direction::Up);
 | 
					 | 
				
			||||||
        if(g != gestures.end())
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            if (g->second->mode == GestureMode::Axis)
 | 
					 | 
				
			||||||
                global_evdev->moveAxis(g->second->axis.code, abs(m.y) * g->second->axis.multiplier);
 | 
					 | 
				
			||||||
            if (g->second->mode == GestureMode::OnFewPixels)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                g->second->per_pixel_mod += abs(m.y);
 | 
					 | 
				
			||||||
                if(g->second->per_pixel_mod >= g->second->per_pixel)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    g->second->per_pixel_mod -= g->second->per_pixel;
 | 
					 | 
				
			||||||
                    g->second->action->press();
 | 
					 | 
				
			||||||
                    g->second->action->release();
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if(m.x != 0 && abs(x) > 50)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        auto g = gestures.find(m.x > 0 ? Direction::Right : Direction::Left);
 | 
					 | 
				
			||||||
        if(g != gestures.end())
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            if (g->second->mode == GestureMode::Axis)
 | 
					 | 
				
			||||||
                global_evdev->moveAxis(g->second->axis.code, abs(m.x) * g->second->axis.multiplier);
 | 
					 | 
				
			||||||
            if (g->second->mode == GestureMode::OnFewPixels)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                g->second->per_pixel_mod += abs(m.x);
 | 
					 | 
				
			||||||
                if (g->second->per_pixel_mod >= g->second->per_pixel)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    g->second->per_pixel_mod -= g->second->per_pixel;
 | 
					 | 
				
			||||||
                    g->second->action->press();
 | 
					 | 
				
			||||||
                    g->second->action->release();
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void GestureAction::release()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    held = false;
 | 
					 | 
				
			||||||
    Direction direction;
 | 
					 | 
				
			||||||
    if(abs(x) < 50 && abs(y) < 50) direction = Direction::None;
 | 
					 | 
				
			||||||
    else direction = getDirection(x, y);
 | 
					 | 
				
			||||||
    x = 0;
 | 
					 | 
				
			||||||
    y = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    auto g = gestures.find(direction);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if(g != gestures.end() && g->second->mode == GestureMode::OnRelease)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        g->second->action->press();
 | 
					 | 
				
			||||||
        g->second->action->release();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void SmartshiftAction::press()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    try
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        HIDPP20::ISmartShift iss(device->hidpp_dev);
 | 
					 | 
				
			||||||
        auto s = iss.getStatus();
 | 
					 | 
				
			||||||
        iss.setStatus({new bool(!*s.Active)});
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    catch(HIDPP20::Error &e)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        log_printf(ERROR, "Error toggling smart shift, code %d: %s\n", e.errorCode(), e.what());
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void HiresScrollAction::press()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    try
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        HIDPP20::IHiresScroll ihs(device->hidpp_dev);
 | 
					 | 
				
			||||||
        auto mode = ihs.getMode();
 | 
					 | 
				
			||||||
        mode ^= HIDPP20::IHiresScroll::Mode::HiRes;
 | 
					 | 
				
			||||||
        ihs.setMode(mode);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    catch(HIDPP20::Error &e)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        log_printf(ERROR, "Error toggling hires scroll, code %d: %s\n", e.errorCode(), e.what());
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void CycleDPIAction::press()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    HIDPP20::IAdjustableDPI iad(device->hidpp_dev);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    try
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        for (uint i = 0; i < iad.getSensorCount(); i++)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            int current_dpi = std::get<0>(iad.getSensorDPI(i));
 | 
					 | 
				
			||||||
            bool found = false;
 | 
					 | 
				
			||||||
            for (uint j = 0; j < dpis.size(); j++)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                if (dpis[j] == current_dpi)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    if (j == dpis.size() - 1)
 | 
					 | 
				
			||||||
                        iad.setSensorDPI(i, dpis[0]);
 | 
					 | 
				
			||||||
                    else
 | 
					 | 
				
			||||||
                        iad.setSensorDPI(i, dpis[j + 1]);
 | 
					 | 
				
			||||||
                    found = true;
 | 
					 | 
				
			||||||
                    break;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (found) break;
 | 
					 | 
				
			||||||
            if (dpis.empty()) iad.setSensorDPI(i, std::get<1>(iad.getSensorDPI(i)));
 | 
					 | 
				
			||||||
            else iad.setSensorDPI(i, dpis[0]);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    catch(HIDPP20::Error &e) { log_printf(ERROR, "Error while cycling DPI: %s", e.what()); }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void ChangeDPIAction::press()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    HIDPP20::IAdjustableDPI iad(device->hidpp_dev);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    try
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        for(uint i = 0; i < iad.getSensorCount(); i++)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            int current_dpi = std::get<0>(iad.getSensorDPI(i));
 | 
					 | 
				
			||||||
            iad.setSensorDPI(i, current_dpi + dpi_inc);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    catch(HIDPP20::Error &e)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        log_printf(ERROR, "Error while incrementing DPI: %s", e.what());
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,164 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright 2019-2020 PixlOne
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation, either version 3 of the License, or
 | 
					 | 
				
			||||||
 * (at your option) any later version.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifndef LOGID_ACTIONS_H
 | 
					 | 
				
			||||||
#define LOGID_ACTIONS_H
 | 
					 | 
				
			||||||
#include "Device.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <map>
 | 
					 | 
				
			||||||
#include <vector>
 | 
					 | 
				
			||||||
#include <hidpp20/IReprogControls.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace logid
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    enum class Action
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        None,
 | 
					 | 
				
			||||||
        Keypress,
 | 
					 | 
				
			||||||
        Gestures,
 | 
					 | 
				
			||||||
        CycleDPI,
 | 
					 | 
				
			||||||
        ChangeDPI,
 | 
					 | 
				
			||||||
        ToggleSmartshift,
 | 
					 | 
				
			||||||
        ToggleHiresScroll
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
    enum class Direction
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        None,
 | 
					 | 
				
			||||||
        Up,
 | 
					 | 
				
			||||||
        Down,
 | 
					 | 
				
			||||||
        Left,
 | 
					 | 
				
			||||||
        Right
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
    enum class GestureMode
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        NoPress,
 | 
					 | 
				
			||||||
        OnRelease,
 | 
					 | 
				
			||||||
        OnFewPixels,
 | 
					 | 
				
			||||||
        Axis
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    class Device;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    class ButtonAction
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
    public:
 | 
					 | 
				
			||||||
        virtual ~ButtonAction() = default;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Action type;
 | 
					 | 
				
			||||||
        virtual ButtonAction* copy(Device* dev) = 0;
 | 
					 | 
				
			||||||
        virtual void press() = 0;
 | 
					 | 
				
			||||||
        virtual void release() = 0;
 | 
					 | 
				
			||||||
    //    ButtonAction(const ButtonAction &a, Device* d) : type (a.type), device (d) {}
 | 
					 | 
				
			||||||
    //    ButtonAction* create_instance(Device* d);
 | 
					 | 
				
			||||||
    protected:
 | 
					 | 
				
			||||||
        ButtonAction(Action a) : type (a) {};
 | 
					 | 
				
			||||||
        Device* device;
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
    class NoAction : public ButtonAction
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
    public:
 | 
					 | 
				
			||||||
        NoAction() : ButtonAction(Action::None) {}
 | 
					 | 
				
			||||||
        virtual NoAction* copy(Device* dev);
 | 
					 | 
				
			||||||
        virtual void press() {}
 | 
					 | 
				
			||||||
        virtual void release() {}
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
    class KeyAction : public ButtonAction
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
    public:
 | 
					 | 
				
			||||||
        explicit KeyAction(std::vector<unsigned int> k) : ButtonAction(Action::Keypress), keys (std::move(k)) {};
 | 
					 | 
				
			||||||
        virtual KeyAction* copy(Device* dev);
 | 
					 | 
				
			||||||
        virtual void press();
 | 
					 | 
				
			||||||
        virtual void release();
 | 
					 | 
				
			||||||
    private:
 | 
					 | 
				
			||||||
        std::vector<unsigned int> keys;
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
    class Gesture
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
    public:
 | 
					 | 
				
			||||||
        struct axis_info {
 | 
					 | 
				
			||||||
            uint code;
 | 
					 | 
				
			||||||
            float multiplier;
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Gesture(ButtonAction* ba, GestureMode m, void* aux=nullptr);
 | 
					 | 
				
			||||||
        Gesture(const Gesture &g, Device* dev)
 | 
					 | 
				
			||||||
                : action (g.action->copy(dev)), mode (g.mode), per_pixel (g.per_pixel),
 | 
					 | 
				
			||||||
                  axis (g.axis)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        ButtonAction* action;
 | 
					 | 
				
			||||||
        GestureMode mode;
 | 
					 | 
				
			||||||
        int per_pixel;
 | 
					 | 
				
			||||||
        int per_pixel_mod;
 | 
					 | 
				
			||||||
        axis_info axis;
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    class GestureAction : public ButtonAction
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
    public:
 | 
					 | 
				
			||||||
        GestureAction(std::map<Direction, Gesture*> g) : ButtonAction(Action::Gestures), gestures (std::move(g)) {};
 | 
					 | 
				
			||||||
        std::map<Direction, Gesture*> gestures;
 | 
					 | 
				
			||||||
        virtual GestureAction* copy(Device* dev);
 | 
					 | 
				
			||||||
        virtual void press();
 | 
					 | 
				
			||||||
        virtual void release();
 | 
					 | 
				
			||||||
        void move(HIDPP20::IReprogControlsV4::Move m);
 | 
					 | 
				
			||||||
    private:
 | 
					 | 
				
			||||||
        bool held;
 | 
					 | 
				
			||||||
        int x = 0;
 | 
					 | 
				
			||||||
        int y = 0;
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
    class SmartshiftAction : public ButtonAction
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
    public:
 | 
					 | 
				
			||||||
        SmartshiftAction() : ButtonAction(Action::ToggleSmartshift) {};
 | 
					 | 
				
			||||||
        virtual SmartshiftAction* copy(Device* dev);
 | 
					 | 
				
			||||||
        virtual void press();
 | 
					 | 
				
			||||||
        virtual void release() {}
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
    class HiresScrollAction : public ButtonAction
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
    public:
 | 
					 | 
				
			||||||
        HiresScrollAction() : ButtonAction(Action::ToggleHiresScroll) {};
 | 
					 | 
				
			||||||
        virtual HiresScrollAction* copy(Device* dev);
 | 
					 | 
				
			||||||
        virtual void press();
 | 
					 | 
				
			||||||
        virtual void release() {}
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
    class CycleDPIAction : public ButtonAction
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
    public:
 | 
					 | 
				
			||||||
        CycleDPIAction(std::vector<int> d) : ButtonAction(Action::CycleDPI), dpis (d) {};
 | 
					 | 
				
			||||||
        virtual CycleDPIAction* copy(Device* dev);
 | 
					 | 
				
			||||||
        virtual void press();
 | 
					 | 
				
			||||||
        virtual void release() {}
 | 
					 | 
				
			||||||
    private:
 | 
					 | 
				
			||||||
        const std::vector<int> dpis;
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
    class ChangeDPIAction : public ButtonAction
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
    public:
 | 
					 | 
				
			||||||
        ChangeDPIAction(int i) : ButtonAction(Action::ChangeDPI), dpi_inc (i) {};
 | 
					 | 
				
			||||||
        virtual ChangeDPIAction* copy(Device* dev);
 | 
					 | 
				
			||||||
        virtual void press();
 | 
					 | 
				
			||||||
        virtual void release() {}
 | 
					 | 
				
			||||||
    private:
 | 
					 | 
				
			||||||
        int dpi_inc;
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif //LOGID_ACTIONS_H
 | 
					 | 
				
			||||||
@@ -1,123 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright 2019-2020 PixlOne
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation, either version 3 of the License, or
 | 
					 | 
				
			||||||
 * (at your option) any later version.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <cstdio>
 | 
					 | 
				
			||||||
#include <string>
 | 
					 | 
				
			||||||
#include <cstring>
 | 
					 | 
				
			||||||
#include <cstdarg>
 | 
					 | 
				
			||||||
#include <cmath>
 | 
					 | 
				
			||||||
#include <algorithm>
 | 
					 | 
				
			||||||
#include <stdexcept>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "util.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
using namespace logid;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
Direction logid::getDirection(int x, int y)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    if(x == 0 && y == 0) return Direction::None;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    double angle;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if(x == 0 && y > 0) angle = 90; // Y+
 | 
					 | 
				
			||||||
    else if(x == 0 && y < 0) angle = 270; // Y-
 | 
					 | 
				
			||||||
    else if(x > 0 && y == 0) angle = 0; // X+
 | 
					 | 
				
			||||||
    else if(x < 0 && y == 0) angle = 180; // X+
 | 
					 | 
				
			||||||
    else
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        angle = fabs(atan((double)y/(double)x) * 180.0 / M_PI);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if(x < 0 && y > 0) angle = 180.0 - angle; //Q2
 | 
					 | 
				
			||||||
        else if(x < 0 && y < 0) angle += 180; // Q3
 | 
					 | 
				
			||||||
        else if(x > 0 && y < 0) angle = 360.0 - angle; // Q4
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if(315 < angle || angle <= 45) return Direction::Right;
 | 
					 | 
				
			||||||
    else if(45 < angle && angle <= 135) return Direction::Down;
 | 
					 | 
				
			||||||
    else if(135 < angle && angle <= 225) return Direction::Left;
 | 
					 | 
				
			||||||
    else if(225 < angle && angle <= 315) return Direction::Up;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return Direction::None;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Direction logid::stringToDirection(std::string s)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    const char* original_str = s.c_str();
 | 
					 | 
				
			||||||
    std::transform(s.begin(), s.end(), s.begin(), ::tolower);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if(s == "none") return Direction::None;
 | 
					 | 
				
			||||||
    if(s == "up") return Direction::Up;
 | 
					 | 
				
			||||||
    if(s == "down") return Direction::Down;
 | 
					 | 
				
			||||||
    if(s == "left") return Direction::Left;
 | 
					 | 
				
			||||||
    if(s == "right") return Direction::Right;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    s = original_str;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    throw std::invalid_argument(s + " is an invalid direction.");
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
GestureMode logid::stringToGestureMode(std::string s)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    const char* original_str = s.c_str();
 | 
					 | 
				
			||||||
    std::transform(s.begin(), s.end(), s.begin(), ::tolower);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if(s == "nopress") return GestureMode::NoPress;
 | 
					 | 
				
			||||||
    if(s == "onrelease") return GestureMode::OnRelease;
 | 
					 | 
				
			||||||
    if(s == "onfewpixels") return GestureMode::OnFewPixels;
 | 
					 | 
				
			||||||
    if(s == "axis") return GestureMode::Axis;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    s = original_str;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    log_printf(INFO, "%s is an invalid gesture mode. Defaulting to OnRelease", original_str);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return GestureMode::OnRelease;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Action logid::stringToAction(std::string s)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    std::string original_str = s;
 | 
					 | 
				
			||||||
    std::transform(s.begin(), s.end(), s.begin(), ::tolower);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if(s == "none") return Action::None;
 | 
					 | 
				
			||||||
    if(s == "keypress") return Action::Keypress;
 | 
					 | 
				
			||||||
    if(s == "gestures") return Action::Gestures;
 | 
					 | 
				
			||||||
    if(s == "togglesmartshift") return Action::ToggleSmartshift;
 | 
					 | 
				
			||||||
    if(s == "togglehiresscroll") return Action::ToggleHiresScroll;
 | 
					 | 
				
			||||||
    if(s == "cycledpi") return Action::CycleDPI;
 | 
					 | 
				
			||||||
    if(s == "changedpi") return Action::ChangeDPI;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    throw std::invalid_argument(original_str + " is an invalid action.");
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
LogLevel logid::stringToLogLevel(std::string s)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    std::string original_str = s;
 | 
					 | 
				
			||||||
    std::transform(s.begin(), s.end(), s.begin(), ::tolower);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if(s == "rawreport") return RAWREPORT;
 | 
					 | 
				
			||||||
    if(s == "debug") return DEBUG;
 | 
					 | 
				
			||||||
    if(s == "info") return INFO;
 | 
					 | 
				
			||||||
    if(s == "warn" || s == "warning") return WARN;
 | 
					 | 
				
			||||||
    if(s == "error") return ERROR;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    throw std::invalid_argument(original_str + " is an invalid log level.");
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,34 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright 2019-2020 PixlOne
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation, either version 3 of the License, or
 | 
					 | 
				
			||||||
 * (at your option) any later version.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifndef LOGID_UTIL_H
 | 
					 | 
				
			||||||
#define LOGID_UTIL_H
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <string>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace logid
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    /*
 | 
					 | 
				
			||||||
    Direction getDirection(int x, int y);
 | 
					 | 
				
			||||||
    Direction stringToDirection(std::string s);
 | 
					 | 
				
			||||||
    GestureMode stringToGestureMode(std::string s);
 | 
					 | 
				
			||||||
    Action stringToAction(std::string s);
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif //LOGID_UTIL_H
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user