Commit d14b4411 authored by Ahmed Ibrahim Khalil's avatar Ahmed Ibrahim Khalil Committed by Albert Vaca Cintora

Implementation of mousepad plugin

CCMAIL: ahmedibrahimkhali@gmail.com
parent 2df8a806
# - Find XTEST
# Find the XTEST libraries
#
# This module defines the following variables:
# XTEST_FOUND - true if XTEST_INCLUDE_DIR & XTEST_LIBRARY are found
# XTEST_LIBRARIES - Set when XTEST_LIBRARY is found
# XTEST_INCLUDE_DIRS - Set when XTEST_INCLUDE_DIR is found
#
# XTEST_INCLUDE_DIR - where to find XTest.h, etc.
# XTEST_LIBRARY - the XTEST library
#
#=============================================================================
# Copyright 2011 O.S. Systems Software Ltda.
# Copyright 2011 Otavio Salvador <otavio@ossystems.com.br>
# Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
find_path(XTEST_INCLUDE_DIR NAMES X11/extensions/XTest.h
PATH_SUFFIXES X11/extensions
DOC "The XTest include directory"
)
find_library(XTEST_LIBRARY NAMES Xtst
DOC "The XTest library"
)
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(XTest DEFAULT_MSG XTEST_LIBRARY XTEST_INCLUDE_DIR)
if(XTEST_FOUND)
set( XTEST_LIBRARIES ${XTEST_LIBRARY} )
set( XTEST_INCLUDE_DIRS ${XTEST_INCLUDE_DIR} )
endif()
mark_as_advanced(XTEST_INCLUDE_DIR XTEST_LIBRARY)
......@@ -7,6 +7,7 @@ add_subdirectory(mpriscontrol)
add_subdirectory(clipboard)
add_subdirectory(telephony)
add_subdirectory(battery)
add_subdirectory(mousepad)
add_subdirectory(share)
add_subdirectory(notifications)
add_subdirectory(sftp)
......
set(kdeconnect_mousepad_SRCS
mousepadplugin.cpp
)
find_package(XTest REQUIRED)
find_package(X11 REQUIRED)
kde4_add_plugin(kdeconnect_mousepad ${kdeconnect_mousepad_SRCS})
include_directories(${XTEST_INCLUDE_DIRS} ${X11_INCLUDE_DIR})
target_link_libraries(kdeconnect_mousepad kdeconnectcore ${QT_QTGUI_LIBRARY} ${X11_LIBRARIES} ${XTEST_LIBRARIES})
install(TARGETS kdeconnect_mousepad DESTINATION ${PLUGIN_INSTALL_DIR} )
install(FILES kdeconnect_mousepad.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
When the user moves his on the phone, dx and dy (The difference between the last movement and the current movement of the X and Y Axis respectively)
is sent inside a NetworkPackage QCursor is used to move mouse cursor according to its relative position.
When the user tap or double taps his phone, a mouse key button is simulated using XTestFakeButtonEvent
[Desktop Entry]
Encoding=UTF-8
Type=Service
ServiceTypes=KdeConnect/Plugin
X-KDE-Library=kdeconnect_mousepad
X-KDE-PluginInfo-Author=Ahmed I. Khalil
X-KDE-PluginInfo-Email=ahmedibrahimkhali@gmail.com
X-KDE-PluginInfo-Name=kdeconnect_mousepad
X-KDE-PluginInfo-Version=0.1
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
Icon=input-mouse
Name=Mousepad
Name[bg]=Буфер за обмен
Name[bs]=Mousepad
Name[ca]=Porta-retalls
Name[cs]=Schránka
Name[da]=Udklipsholder
Name[de]=Zwischenablage
Name[es]=Portapapeles
Name[fr]=Presse-papiers
Name[hu]=Vágólap
Name[it]=Appunti
Name[ko]=클립보드
Name[nl]=Klembord
Name[pl]=Schowek
Name[pt]=Área de Transferência
Name[pt_BR]=Área de transferência
Name[ro]=Mousepad
Name[ru]=Буфер обмена
Name[sk]=Schránka
Name[sv]=Klippbord
Name[tr]=Pano
Name[uk]=Буфер обміну
Name[x-test]=xxMousepadxx
Comment=Use your phone as a mousepad
Comment[bg]=Споделяне на буфера за обмен между устройства
Comment[bs]=Podijeli Mousepad među uređajima
Comment[ca]=Comparteix el porta-retalls entre els dispositius
Comment[cs]=Sdílejte schránku mezi zařízeními
Comment[da]=Del indholdet af udklipsholderen mellem enheder
Comment[de]=Die Zwischenablage mit Geräten teilen
Comment[es]=Compartir el portapapeles entre dispositivos
Comment[fr]=Partagez le presse-papiers entre périphériques
Comment[hu]=Vágólap megosztása az eszközök között
Comment[it]=Condividi gli appunti tra i dispositivi
Comment[ko]=장치간 클립보드 공유
Comment[nl]=Het klembord tussen apparaten delen
Comment[pl]=Współdziel schowek pomiędzy urządzeniami
Comment[pt]=Partilhar a área de transferência entre dispositivos
Comment[pt_BR]=Compartilhar a área de transferência entre dispositivos
Comment[ro]=Partajează clipboardul între dispozitive
Comment[ru]=Общий буфер обмена для всех устройств
Comment[sk]=Zdieľať schránku medzi zariadeniami
Comment[sv]=Dela klippbordet mellan apparater
Comment[tr]=Aygıtlar arasında panoyu paylaştır
Comment[uk]=Спільне використання буфера обміну даними на пристроях
Comment[x-test]=xxShare the clipboard between devicesxx
X-KdeConnect-SupportedPackageType=kdeconnect.mousepad
X-KdeConnect-OutgoingPackageType=kdeconnect.mousepad
/**
* Copyright 2014 Ahmed I. Khalil <ahmedibrahimkhali@gmail.com>
*
* 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 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* 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 "mousepadplugin.h"
#include <core/networkpackage.h>
#include <QApplication>
#include <X11/extensions/XTest.h>
K_PLUGIN_FACTORY( KdeConnectPluginFactory, registerPlugin< MousepadPlugin >(); )
K_EXPORT_PLUGIN( KdeConnectPluginFactory("kdeconnect_mousepad", "kdeconnect-plugins") )
#define LEFT_MOUSE_BUTTON 1 // Source: http://bharathisubramanian.wordpress.com/2010/04/01/x11-fake-mouse-events-generation-using-xtest/
MousepadPlugin::MousepadPlugin(QObject* parent, const QVariantList& args)
: KdeConnectPlugin(parent, args)
{
}
bool MousepadPlugin::receivePackage(const NetworkPackage& np)
{
float dx = np.get<float>("dx", 0);
float dy = np.get<float>("dy", 0);
QPoint point = QCursor::pos();
QCursor::setPos(point.x() + (int)dx, point.y() + (int)dy);
bool isSingleClick = np.get<bool>("singleclick", false);
bool isDoubleClick = np.get<bool>("doubleclick", false);
if (isSingleClick || isDoubleClick) {
Display *display = XOpenDisplay(NULL);
if(display) {
if (isSingleClick) {
XTestFakeButtonEvent(display, LEFT_MOUSE_BUTTON, true, CurrentTime);
XTestFakeButtonEvent(display, LEFT_MOUSE_BUTTON, false, CurrentTime);
} else if (isDoubleClick) {
XTestFakeButtonEvent(display, LEFT_MOUSE_BUTTON, true, CurrentTime);
XTestFakeButtonEvent(display, LEFT_MOUSE_BUTTON, false, CurrentTime);
XTestFakeButtonEvent(display, LEFT_MOUSE_BUTTON, true, CurrentTime);
XTestFakeButtonEvent(display, LEFT_MOUSE_BUTTON, false, CurrentTime);
}
XFlush(display);
}
XCloseDisplay(display);
}
return true;
}
/**
* Copyright 2014 Ahmed I. Khalil <albertvaka@gmail.com>
*
* 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 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* 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 MOUSEPADPLUGIN_H
#define MOUSEPADPLUGIN_H
#include <QObject>
#include <core/kdeconnectplugin.h>
#define PACKAGE_TYPE_MOUSEPAD QLatin1String("kdeconnect.mousepad")
class MousepadPlugin
: public KdeConnectPlugin
{
Q_OBJECT
public:
explicit MousepadPlugin(QObject *parent, const QVariantList &args);
public Q_SLOTS:
virtual bool receivePackage(const NetworkPackage& np);
virtual void connected() { }
};
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment