reverting trunk back to stable 3.4.1 version
git-svn-id: svn://svn.code.sf.net/p/qjoypad/code/trunk@82 c05e91a0-76c8-4ec0-b377-ef19ce7cc080
This commit is contained in:
committed by
virtuoussin13
parent
1cc6e9087e
commit
17ed926cdf
745
src/Makefile
745
src/Makefile
@ -1,48 +1,74 @@
|
|||||||
#############################################################################
|
#############################################################################
|
||||||
# Makefile for building: qjoypad
|
# Makefile for building: qjoypad
|
||||||
# Generated by qmake (2.01a) (Qt 4.5.1) on: Mon May 25 00:43:37 2009
|
# Generated by qmake (1.07a) (Qt 3.3.6) on: Wed Nov 1 12:59:29 2006
|
||||||
# Project: qjoypad.pro
|
# Project: qjoypad.pro
|
||||||
# Template: app
|
# Template: app
|
||||||
# Command: /usr/bin/qmake -unix -o Makefile qjoypad.pro
|
# Command: $(QMAKE) "DEVDIR=/dev/input" "PREFIX=/usr" "DEFINES += " -o Makefile qjoypad.pro
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
||||||
####### Compiler, tools and options
|
####### Compiler, tools and options
|
||||||
|
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CXX = g++
|
CXX = g++
|
||||||
DEFINES = -DDEVDIR="" -DICON24="/share/pixmaps/qjoypad/icon24.png" -DICON64="/share/pixmaps/qjoypad/icon64.png" -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
|
LEX = flex
|
||||||
CFLAGS = -pipe -march=i686 -mtune=generic -O2 -pipe -Wall -W -D_REENTRANT $(DEFINES)
|
YACC = yacc
|
||||||
CXXFLAGS = -pipe -march=i686 -mtune=generic -O2 -pipe -Wall -W -D_REENTRANT $(DEFINES)
|
CFLAGS = -pipe -Wall -W -O2 -D_REENTRANT -DDEVDIR='"/dev/input"' -DICON24='"/usr/share/pixmaps/qjoypad/icon24.png"' -DICON64='"/usr/share/pixmaps/qjoypad/icon64.png"' -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -DQT_SHARED -DQT_TABLET_SUPPORT
|
||||||
INCPATH = -I/usr/share/qt/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I. -Itrayicon -I. -I.
|
CXXFLAGS = -pipe -Wall -W -O2 -D_REENTRANT -DDEVDIR='"/dev/input"' -DICON24='"/usr/share/pixmaps/qjoypad/icon24.png"' -DICON64='"/usr/share/pixmaps/qjoypad/icon64.png"' -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -DQT_SHARED -DQT_TABLET_SUPPORT
|
||||||
LINK = g++
|
LEXFLAGS =
|
||||||
LFLAGS = -Wl,-O1 -Wl,-rpath,/usr/lib
|
YACCFLAGS= -d
|
||||||
LIBS = $(SUBLIBS) -L/usr/lib -lXtst -lQtGui -L/usr/lib -L/usr/X11R6/lib -pthread -lpng -lfreetype -lgobject-2.0 -lSM -lICE -pthread -pthread -lXrender -lfontconfig -lXext -lX11 -lQtCore -lz -lm -pthread -lgthread-2.0 -lrt -lglib-2.0 -ldl -lpthread
|
INCPATH = -I/usr/share/qt3/mkspecs/default -I. -I. -Itrayicon -I/usr/include/qt3
|
||||||
AR = ar cqs
|
LINK = g++
|
||||||
RANLIB =
|
LFLAGS =
|
||||||
QMAKE = /usr/bin/qmake
|
LIBS = $(SUBLIBS) -L/usr/share/qt3/lib -L/usr/X11R6/lib -lXtst -lqt-mt -lXext -lX11 -lm -lpthread
|
||||||
TAR = tar -cf
|
AR = ar cqs
|
||||||
COMPRESS = gzip -9f
|
RANLIB =
|
||||||
COPY = cp -f
|
MOC = /usr/share/qt3/bin/moc
|
||||||
SED = sed
|
UIC = /usr/share/qt3/bin/uic
|
||||||
COPY_FILE = $(COPY)
|
QMAKE = qmake
|
||||||
COPY_DIR = $(COPY) -r
|
TAR = tar -cf
|
||||||
INSTALL_FILE = install -m 644 -p
|
GZIP = gzip -9f
|
||||||
INSTALL_DIR = $(COPY_DIR)
|
COPY = cp -f
|
||||||
INSTALL_PROGRAM = install -m 755 -p
|
COPY_FILE= $(COPY)
|
||||||
DEL_FILE = rm -f
|
COPY_DIR = $(COPY) -r
|
||||||
SYMLINK = ln -sf
|
INSTALL_FILE= $(COPY_FILE)
|
||||||
DEL_DIR = rmdir
|
INSTALL_DIR = $(COPY_DIR)
|
||||||
MOVE = mv -f
|
DEL_FILE = rm -f
|
||||||
|
SYMLINK = ln -sf
|
||||||
|
DEL_DIR = rmdir
|
||||||
|
MOVE = mv -f
|
||||||
CHK_DIR_EXISTS= test -d
|
CHK_DIR_EXISTS= test -d
|
||||||
MKDIR = mkdir -p
|
MKDIR = mkdir -p
|
||||||
|
|
||||||
####### Output directory
|
####### Output directory
|
||||||
|
|
||||||
OBJECTS_DIR = ./
|
OBJECTS_DIR = ./
|
||||||
|
|
||||||
####### Files
|
####### Files
|
||||||
|
|
||||||
SOURCES = axis.cpp \
|
HEADERS = axis.h \
|
||||||
|
axis_edit.h \
|
||||||
|
axisw.h \
|
||||||
|
button.h \
|
||||||
|
button_edit.h \
|
||||||
|
buttonw.h \
|
||||||
|
component.h \
|
||||||
|
constant.h \
|
||||||
|
device.h \
|
||||||
|
error.h \
|
||||||
|
event.h \
|
||||||
|
flash.h \
|
||||||
|
icon.h \
|
||||||
|
joypad.h \
|
||||||
|
joypadw.h \
|
||||||
|
joyslider.h \
|
||||||
|
keycode.h \
|
||||||
|
layout.h \
|
||||||
|
layout_edit.h \
|
||||||
|
loop.h \
|
||||||
|
quickset.h \
|
||||||
|
timer.h \
|
||||||
|
trayicon/trayicon.h
|
||||||
|
SOURCES = axis.cpp \
|
||||||
axis_edit.cpp \
|
axis_edit.cpp \
|
||||||
axisw.cpp \
|
axisw.cpp \
|
||||||
button.cpp \
|
button.cpp \
|
||||||
@ -57,23 +83,12 @@ SOURCES = axis.cpp \
|
|||||||
keycode.cpp \
|
keycode.cpp \
|
||||||
layout.cpp \
|
layout.cpp \
|
||||||
layout_edit.cpp \
|
layout_edit.cpp \
|
||||||
|
loop.cpp \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
quickset.cpp \
|
quickset.cpp \
|
||||||
getkey.cpp \
|
|
||||||
trayicon/trayicon.cpp \
|
trayicon/trayicon.cpp \
|
||||||
trayicon/trayicon_x11.cpp moc_axis.cpp \
|
trayicon/trayicon_x11.cpp
|
||||||
moc_axis_edit.cpp \
|
OBJECTS = axis.o \
|
||||||
moc_button.cpp \
|
|
||||||
moc_button_edit.cpp \
|
|
||||||
moc_flash.cpp \
|
|
||||||
moc_icon.cpp \
|
|
||||||
moc_joypad.cpp \
|
|
||||||
moc_joypadw.cpp \
|
|
||||||
moc_keycode.cpp \
|
|
||||||
moc_layout.cpp \
|
|
||||||
moc_getkey.cpp \
|
|
||||||
moc_trayicon.cpp
|
|
||||||
OBJECTS = axis.o \
|
|
||||||
axis_edit.o \
|
axis_edit.o \
|
||||||
axisw.o \
|
axisw.o \
|
||||||
button.o \
|
button.o \
|
||||||
@ -88,126 +103,85 @@ OBJECTS = axis.o \
|
|||||||
keycode.o \
|
keycode.o \
|
||||||
layout.o \
|
layout.o \
|
||||||
layout_edit.o \
|
layout_edit.o \
|
||||||
|
loop.o \
|
||||||
main.o \
|
main.o \
|
||||||
quickset.o \
|
quickset.o \
|
||||||
getkey.o \
|
|
||||||
trayicon.o \
|
trayicon.o \
|
||||||
trayicon_x11.o \
|
trayicon_x11.o
|
||||||
moc_axis.o \
|
FORMS =
|
||||||
moc_axis_edit.o \
|
UICDECLS =
|
||||||
moc_button.o \
|
UICIMPLS =
|
||||||
|
SRCMOC = moc_axis_edit.cpp \
|
||||||
|
moc_button_edit.cpp \
|
||||||
|
moc_flash.cpp \
|
||||||
|
moc_icon.cpp \
|
||||||
|
moc_joypadw.cpp \
|
||||||
|
moc_keycode.cpp \
|
||||||
|
moc_layout.cpp \
|
||||||
|
trayicon/moc_trayicon.cpp
|
||||||
|
OBJMOC = moc_axis_edit.o \
|
||||||
moc_button_edit.o \
|
moc_button_edit.o \
|
||||||
moc_flash.o \
|
moc_flash.o \
|
||||||
moc_icon.o \
|
moc_icon.o \
|
||||||
moc_joypad.o \
|
|
||||||
moc_joypadw.o \
|
moc_joypadw.o \
|
||||||
moc_keycode.o \
|
moc_keycode.o \
|
||||||
moc_layout.o \
|
moc_layout.o \
|
||||||
moc_getkey.o \
|
|
||||||
moc_trayicon.o
|
moc_trayicon.o
|
||||||
DIST = /usr/share/qt/mkspecs/common/g++.conf \
|
DIST = qjoypad.pro
|
||||||
/usr/share/qt/mkspecs/common/unix.conf \
|
QMAKE_TARGET = qjoypad
|
||||||
/usr/share/qt/mkspecs/common/linux.conf \
|
DESTDIR =
|
||||||
/usr/share/qt/mkspecs/qconfig.pri \
|
TARGET = qjoypad
|
||||||
/usr/share/qt/mkspecs/features/qt_functions.prf \
|
|
||||||
/usr/share/qt/mkspecs/features/qt_config.prf \
|
|
||||||
/usr/share/qt/mkspecs/features/exclusive_builds.prf \
|
|
||||||
/usr/share/qt/mkspecs/features/default_pre.prf \
|
|
||||||
/usr/share/qt/mkspecs/features/release.prf \
|
|
||||||
/usr/share/qt/mkspecs/features/default_post.prf \
|
|
||||||
/usr/share/qt/mkspecs/features/warn_on.prf \
|
|
||||||
/usr/share/qt/mkspecs/features/qt.prf \
|
|
||||||
/usr/share/qt/mkspecs/features/unix/thread.prf \
|
|
||||||
/usr/share/qt/mkspecs/features/moc.prf \
|
|
||||||
/usr/share/qt/mkspecs/features/resources.prf \
|
|
||||||
/usr/share/qt/mkspecs/features/uic.prf \
|
|
||||||
/usr/share/qt/mkspecs/features/yacc.prf \
|
|
||||||
/usr/share/qt/mkspecs/features/lex.prf \
|
|
||||||
/usr/share/qt/mkspecs/features/include_source_dir.prf \
|
|
||||||
qjoypad.pro
|
|
||||||
QMAKE_TARGET = qjoypad
|
|
||||||
DESTDIR =
|
|
||||||
TARGET = qjoypad
|
|
||||||
|
|
||||||
first: all
|
first: all
|
||||||
####### Implicit rules
|
####### Implicit rules
|
||||||
|
|
||||||
.SUFFIXES: .o .c .cpp .cc .cxx .C
|
.SUFFIXES: .c .o .cpp .cc .cxx .C
|
||||||
|
|
||||||
.cpp.o:
|
.cpp.o:
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
|
||||||
|
|
||||||
.cc.o:
|
.cc.o:
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
|
||||||
|
|
||||||
.cxx.o:
|
.cxx.o:
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
|
||||||
|
|
||||||
.C.o:
|
.C.o:
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
$(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<"
|
$(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
|
||||||
|
|
||||||
####### Build rules
|
####### Build rules
|
||||||
|
|
||||||
all: Makefile $(TARGET)
|
all: Makefile $(TARGET)
|
||||||
|
|
||||||
$(TARGET): $(OBJECTS)
|
$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC)
|
||||||
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
|
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJMOC) $(OBJCOMP) $(LIBS)
|
||||||
|
|
||||||
Makefile: qjoypad.pro /usr/share/qt/mkspecs/linux-g++/qmake.conf /usr/share/qt/mkspecs/common/g++.conf \
|
mocables: $(SRCMOC)
|
||||||
/usr/share/qt/mkspecs/common/unix.conf \
|
uicables: $(UICDECLS) $(UICIMPLS)
|
||||||
/usr/share/qt/mkspecs/common/linux.conf \
|
|
||||||
/usr/share/qt/mkspecs/qconfig.pri \
|
$(MOC):
|
||||||
/usr/share/qt/mkspecs/features/qt_functions.prf \
|
( cd $(QTDIR)/src/moc && $(MAKE) )
|
||||||
/usr/share/qt/mkspecs/features/qt_config.prf \
|
|
||||||
/usr/share/qt/mkspecs/features/exclusive_builds.prf \
|
Makefile: qjoypad.pro /usr/share/qt3/mkspecs/default/qmake.conf /usr/share/qt3/lib/libqt-mt.prl
|
||||||
/usr/share/qt/mkspecs/features/default_pre.prf \
|
$(QMAKE) "DEVDIR=/dev/input" "PREFIX=/usr" "DEFINES += " -o Makefile qjoypad.pro
|
||||||
/usr/share/qt/mkspecs/features/release.prf \
|
qmake:
|
||||||
/usr/share/qt/mkspecs/features/default_post.prf \
|
@$(QMAKE) "DEVDIR=/dev/input" "PREFIX=/usr" "DEFINES += " -o Makefile qjoypad.pro
|
||||||
/usr/share/qt/mkspecs/features/warn_on.prf \
|
|
||||||
/usr/share/qt/mkspecs/features/qt.prf \
|
|
||||||
/usr/share/qt/mkspecs/features/unix/thread.prf \
|
|
||||||
/usr/share/qt/mkspecs/features/moc.prf \
|
|
||||||
/usr/share/qt/mkspecs/features/resources.prf \
|
|
||||||
/usr/share/qt/mkspecs/features/uic.prf \
|
|
||||||
/usr/share/qt/mkspecs/features/yacc.prf \
|
|
||||||
/usr/share/qt/mkspecs/features/lex.prf \
|
|
||||||
/usr/share/qt/mkspecs/features/include_source_dir.prf \
|
|
||||||
/usr/lib/libQtGui.prl \
|
|
||||||
/usr/lib/libQtCore.prl
|
|
||||||
$(QMAKE) -unix -o Makefile qjoypad.pro
|
|
||||||
/usr/share/qt/mkspecs/common/g++.conf:
|
|
||||||
/usr/share/qt/mkspecs/common/unix.conf:
|
|
||||||
/usr/share/qt/mkspecs/common/linux.conf:
|
|
||||||
/usr/share/qt/mkspecs/qconfig.pri:
|
|
||||||
/usr/share/qt/mkspecs/features/qt_functions.prf:
|
|
||||||
/usr/share/qt/mkspecs/features/qt_config.prf:
|
|
||||||
/usr/share/qt/mkspecs/features/exclusive_builds.prf:
|
|
||||||
/usr/share/qt/mkspecs/features/default_pre.prf:
|
|
||||||
/usr/share/qt/mkspecs/features/release.prf:
|
|
||||||
/usr/share/qt/mkspecs/features/default_post.prf:
|
|
||||||
/usr/share/qt/mkspecs/features/warn_on.prf:
|
|
||||||
/usr/share/qt/mkspecs/features/qt.prf:
|
|
||||||
/usr/share/qt/mkspecs/features/unix/thread.prf:
|
|
||||||
/usr/share/qt/mkspecs/features/moc.prf:
|
|
||||||
/usr/share/qt/mkspecs/features/resources.prf:
|
|
||||||
/usr/share/qt/mkspecs/features/uic.prf:
|
|
||||||
/usr/share/qt/mkspecs/features/yacc.prf:
|
|
||||||
/usr/share/qt/mkspecs/features/lex.prf:
|
|
||||||
/usr/share/qt/mkspecs/features/include_source_dir.prf:
|
|
||||||
/usr/lib/libQtGui.prl:
|
|
||||||
/usr/lib/libQtCore.prl:
|
|
||||||
qmake: FORCE
|
|
||||||
@$(QMAKE) -unix -o Makefile qjoypad.pro
|
|
||||||
|
|
||||||
dist:
|
dist:
|
||||||
@$(CHK_DIR_EXISTS) .tmp/qjoypad1.0.0 || $(MKDIR) .tmp/qjoypad1.0.0
|
@mkdir -p .tmp/qjoypad && $(COPY_FILE) --parents $(SOURCES) $(HEADERS) $(FORMS) $(DIST) .tmp/qjoypad/ && ( cd `dirname .tmp/qjoypad` && $(TAR) qjoypad.tar qjoypad && $(GZIP) qjoypad.tar ) && $(MOVE) `dirname .tmp/qjoypad`/qjoypad.tar.gz . && $(DEL_FILE) -r .tmp/qjoypad
|
||||||
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/qjoypad1.0.0/ && $(COPY_FILE) --parents axis.h axis_edit.h axisw.h button.h button_edit.h buttonw.h constant.h device.h error.h event.h flash.h icon.h joypad.h joypadw.h joyslider.h keycode.h layout.h getkey.h layout_edit.h quickset.h trayicon/trayicon.h .tmp/qjoypad1.0.0/ && $(COPY_FILE) --parents axis.cpp axis_edit.cpp axisw.cpp button.cpp button_edit.cpp buttonw.cpp event.cpp flash.cpp icon.cpp joypad.cpp joypadw.cpp joyslider.cpp keycode.cpp layout.cpp layout_edit.cpp main.cpp quickset.cpp getkey.cpp trayicon/trayicon.cpp trayicon/trayicon_x11.cpp .tmp/qjoypad1.0.0/ && (cd `dirname .tmp/qjoypad1.0.0` && $(TAR) qjoypad1.0.0.tar qjoypad1.0.0 && $(COMPRESS) qjoypad1.0.0.tar) && $(MOVE) `dirname .tmp/qjoypad1.0.0`/qjoypad1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/qjoypad1.0.0
|
|
||||||
|
|
||||||
|
mocclean:
|
||||||
|
-$(DEL_FILE) $(OBJMOC)
|
||||||
|
-$(DEL_FILE) $(SRCMOC)
|
||||||
|
|
||||||
clean:compiler_clean
|
uiclean:
|
||||||
|
|
||||||
|
yaccclean:
|
||||||
|
lexclean:
|
||||||
|
clean: mocclean
|
||||||
-$(DEL_FILE) $(OBJECTS)
|
-$(DEL_FILE) $(OBJECTS)
|
||||||
-$(DEL_FILE) *~ core *.core
|
-$(DEL_FILE) *~ core *.core
|
||||||
|
|
||||||
@ -215,308 +189,220 @@ clean:compiler_clean
|
|||||||
####### Sub-libraries
|
####### Sub-libraries
|
||||||
|
|
||||||
distclean: clean
|
distclean: clean
|
||||||
-$(DEL_FILE) $(TARGET)
|
-$(DEL_FILE) $(TARGET) $(TARGET)
|
||||||
-$(DEL_FILE) Makefile
|
|
||||||
|
|
||||||
|
|
||||||
mocclean: compiler_moc_header_clean compiler_moc_source_clean
|
FORCE:
|
||||||
|
|
||||||
mocables: compiler_moc_header_make_all compiler_moc_source_make_all
|
|
||||||
|
|
||||||
compiler_moc_header_make_all: moc_axis.cpp moc_axis_edit.cpp moc_button.cpp moc_button_edit.cpp moc_flash.cpp moc_icon.cpp moc_joypad.cpp moc_joypadw.cpp moc_keycode.cpp moc_layout.cpp moc_getkey.cpp moc_trayicon.cpp
|
|
||||||
compiler_moc_header_clean:
|
|
||||||
-$(DEL_FILE) moc_axis.cpp moc_axis_edit.cpp moc_button.cpp moc_button_edit.cpp moc_flash.cpp moc_icon.cpp moc_joypad.cpp moc_joypadw.cpp moc_keycode.cpp moc_layout.cpp moc_getkey.cpp moc_trayicon.cpp
|
|
||||||
moc_axis.cpp: constant.h \
|
|
||||||
axis.h
|
|
||||||
/usr/bin/moc $(DEFINES) $(INCPATH) axis.h -o moc_axis.cpp
|
|
||||||
|
|
||||||
moc_axis_edit.cpp: axis.h \
|
|
||||||
constant.h \
|
|
||||||
joyslider.h \
|
|
||||||
keycode.h \
|
|
||||||
axis_edit.h
|
|
||||||
/usr/bin/moc $(DEFINES) $(INCPATH) axis_edit.h -o moc_axis_edit.cpp
|
|
||||||
|
|
||||||
moc_button.cpp: keycode.h \
|
|
||||||
constant.h \
|
|
||||||
button.h
|
|
||||||
/usr/bin/moc $(DEFINES) $(INCPATH) button.h -o moc_button.cpp
|
|
||||||
|
|
||||||
moc_button_edit.cpp: button.h \
|
|
||||||
keycode.h \
|
|
||||||
constant.h \
|
|
||||||
button_edit.h
|
|
||||||
/usr/bin/moc $(DEFINES) $(INCPATH) button_edit.h -o moc_button_edit.cpp
|
|
||||||
|
|
||||||
moc_flash.cpp: flash.h
|
|
||||||
/usr/bin/moc $(DEFINES) $(INCPATH) flash.h -o moc_flash.cpp
|
|
||||||
|
|
||||||
moc_icon.cpp: constant.h \
|
|
||||||
icon.h
|
|
||||||
/usr/bin/moc $(DEFINES) $(INCPATH) icon.h -o moc_icon.cpp
|
|
||||||
|
|
||||||
moc_joypad.cpp: button.h \
|
|
||||||
keycode.h \
|
|
||||||
constant.h \
|
|
||||||
axis.h \
|
|
||||||
joypadw.h \
|
|
||||||
axisw.h \
|
|
||||||
flash.h \
|
|
||||||
axis_edit.h \
|
|
||||||
joyslider.h \
|
|
||||||
joypad.h \
|
|
||||||
error.h \
|
|
||||||
buttonw.h \
|
|
||||||
button_edit.h \
|
|
||||||
quickset.h \
|
|
||||||
joypad.h
|
|
||||||
/usr/bin/moc $(DEFINES) $(INCPATH) joypad.h -o moc_joypad.cpp
|
|
||||||
|
|
||||||
moc_joypadw.cpp: axisw.h \
|
|
||||||
axis.h \
|
|
||||||
constant.h \
|
|
||||||
flash.h \
|
|
||||||
axis_edit.h \
|
|
||||||
joyslider.h \
|
|
||||||
keycode.h \
|
|
||||||
joypad.h \
|
|
||||||
button.h \
|
|
||||||
joypadw.h \
|
|
||||||
buttonw.h \
|
|
||||||
button_edit.h \
|
|
||||||
quickset.h \
|
|
||||||
error.h \
|
|
||||||
joypadw.h
|
|
||||||
/usr/bin/moc $(DEFINES) $(INCPATH) joypadw.h -o moc_joypadw.cpp
|
|
||||||
|
|
||||||
moc_keycode.cpp: constant.h \
|
|
||||||
keycode.h
|
|
||||||
/usr/bin/moc $(DEFINES) $(INCPATH) keycode.h -o moc_keycode.cpp
|
|
||||||
|
|
||||||
moc_layout.cpp: joypad.h \
|
|
||||||
button.h \
|
|
||||||
keycode.h \
|
|
||||||
constant.h \
|
|
||||||
axis.h \
|
|
||||||
joypadw.h \
|
|
||||||
axisw.h \
|
|
||||||
flash.h \
|
|
||||||
axis_edit.h \
|
|
||||||
joyslider.h \
|
|
||||||
buttonw.h \
|
|
||||||
button_edit.h \
|
|
||||||
quickset.h \
|
|
||||||
error.h \
|
|
||||||
device.h \
|
|
||||||
trayicon/trayicon.h \
|
|
||||||
icon.h \
|
|
||||||
layout_edit.h \
|
|
||||||
layout.h \
|
|
||||||
layout.h
|
|
||||||
/usr/bin/moc $(DEFINES) $(INCPATH) layout.h -o moc_layout.cpp
|
|
||||||
|
|
||||||
moc_getkey.cpp: constant.h \
|
|
||||||
getkey.h
|
|
||||||
/usr/bin/moc $(DEFINES) $(INCPATH) getkey.h -o moc_getkey.cpp
|
|
||||||
|
|
||||||
moc_trayicon.cpp: trayicon/trayicon.h
|
|
||||||
/usr/bin/moc $(DEFINES) $(INCPATH) trayicon/trayicon.h -o moc_trayicon.cpp
|
|
||||||
|
|
||||||
compiler_rcc_make_all:
|
|
||||||
compiler_rcc_clean:
|
|
||||||
compiler_image_collection_make_all: qmake_image_collection.cpp
|
|
||||||
compiler_image_collection_clean:
|
|
||||||
-$(DEL_FILE) qmake_image_collection.cpp
|
|
||||||
compiler_moc_source_make_all:
|
|
||||||
compiler_moc_source_clean:
|
|
||||||
compiler_uic_make_all:
|
|
||||||
compiler_uic_clean:
|
|
||||||
compiler_yacc_decl_make_all:
|
|
||||||
compiler_yacc_decl_clean:
|
|
||||||
compiler_yacc_impl_make_all:
|
|
||||||
compiler_yacc_impl_clean:
|
|
||||||
compiler_lex_make_all:
|
|
||||||
compiler_lex_clean:
|
|
||||||
compiler_clean: compiler_moc_header_clean
|
|
||||||
|
|
||||||
####### Compile
|
####### Compile
|
||||||
|
|
||||||
axis.o: axis.cpp axis.h \
|
axis.o: axis.cpp axis.h \
|
||||||
constant.h \
|
component.h \
|
||||||
event.h
|
timer.h \
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o axis.o axis.cpp
|
event.h \
|
||||||
|
constant.h
|
||||||
|
|
||||||
axis_edit.o: axis_edit.cpp axis_edit.h \
|
axis_edit.o: axis_edit.cpp axis_edit.h \
|
||||||
|
joyslider.h \
|
||||||
|
keycode.h \
|
||||||
axis.h \
|
axis.h \
|
||||||
constant.h \
|
constant.h \
|
||||||
joyslider.h \
|
component.h \
|
||||||
keycode.h
|
timer.h \
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o axis_edit.o axis_edit.cpp
|
event.h
|
||||||
|
|
||||||
axisw.o: axisw.cpp axisw.h \
|
axisw.o: axisw.cpp axisw.h \
|
||||||
axis.h \
|
axis.h \
|
||||||
constant.h \
|
|
||||||
flash.h \
|
|
||||||
axis_edit.h \
|
axis_edit.h \
|
||||||
|
flash.h \
|
||||||
|
component.h \
|
||||||
|
timer.h \
|
||||||
|
event.h \
|
||||||
|
constant.h \
|
||||||
joyslider.h \
|
joyslider.h \
|
||||||
keycode.h
|
keycode.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o axisw.o axisw.cpp
|
|
||||||
|
|
||||||
button.o: button.cpp button.h \
|
button.o: button.cpp button.h \
|
||||||
|
component.h \
|
||||||
|
timer.h \
|
||||||
keycode.h \
|
keycode.h \
|
||||||
constant.h \
|
event.h \
|
||||||
event.h
|
constant.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o button.o button.cpp
|
|
||||||
|
|
||||||
button_edit.o: button_edit.cpp button_edit.h \
|
button_edit.o: button_edit.cpp button_edit.h \
|
||||||
button.h \
|
button.h \
|
||||||
keycode.h \
|
keycode.h \
|
||||||
|
component.h \
|
||||||
|
timer.h \
|
||||||
|
event.h \
|
||||||
constant.h
|
constant.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o button_edit.o button_edit.cpp
|
|
||||||
|
|
||||||
buttonw.o: buttonw.cpp buttonw.h \
|
buttonw.o: buttonw.cpp buttonw.h \
|
||||||
button.h \
|
button.h \
|
||||||
keycode.h \
|
|
||||||
constant.h \
|
|
||||||
button_edit.h \
|
button_edit.h \
|
||||||
flash.h
|
flash.h \
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o buttonw.o buttonw.cpp
|
component.h \
|
||||||
|
timer.h \
|
||||||
|
keycode.h \
|
||||||
|
event.h \
|
||||||
|
constant.h
|
||||||
|
|
||||||
event.o: event.cpp event.h
|
event.o: event.cpp event.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o event.o event.cpp
|
|
||||||
|
|
||||||
flash.o: flash.cpp flash.h
|
flash.o: flash.cpp flash.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o flash.o flash.cpp
|
|
||||||
|
|
||||||
icon.o: icon.cpp icon.h \
|
icon.o: icon.cpp icon.h \
|
||||||
constant.h
|
constant.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o icon.o icon.cpp
|
|
||||||
|
|
||||||
joypad.o: joypad.cpp joypad.h \
|
joypad.o: joypad.cpp joypad.h \
|
||||||
button.h \
|
button.h \
|
||||||
keycode.h \
|
|
||||||
constant.h \
|
|
||||||
axis.h \
|
axis.h \
|
||||||
joypadw.h \
|
joypadw.h \
|
||||||
|
error.h \
|
||||||
|
component.h \
|
||||||
|
timer.h \
|
||||||
|
keycode.h \
|
||||||
|
event.h \
|
||||||
|
constant.h \
|
||||||
axisw.h \
|
axisw.h \
|
||||||
flash.h \
|
|
||||||
axis_edit.h \
|
|
||||||
joyslider.h \
|
|
||||||
buttonw.h \
|
buttonw.h \
|
||||||
button_edit.h \
|
|
||||||
quickset.h \
|
quickset.h \
|
||||||
error.h
|
axis_edit.h \
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o joypad.o joypad.cpp
|
flash.h \
|
||||||
|
joyslider.h \
|
||||||
|
button_edit.h
|
||||||
|
|
||||||
joypadw.o: joypadw.cpp joypadw.h \
|
joypadw.o: joypadw.cpp joypadw.h \
|
||||||
axisw.h \
|
|
||||||
axis.h \
|
|
||||||
constant.h \
|
|
||||||
flash.h \
|
|
||||||
axis_edit.h \
|
|
||||||
joyslider.h \
|
|
||||||
keycode.h \
|
|
||||||
joypad.h \
|
joypad.h \
|
||||||
button.h \
|
axisw.h \
|
||||||
error.h \
|
|
||||||
buttonw.h \
|
buttonw.h \
|
||||||
button_edit.h \
|
quickset.h \
|
||||||
quickset.h
|
button.h \
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o joypadw.o joypadw.cpp
|
axis.h \
|
||||||
|
error.h \
|
||||||
|
component.h \
|
||||||
|
timer.h \
|
||||||
|
keycode.h \
|
||||||
|
event.h \
|
||||||
|
constant.h \
|
||||||
|
axis_edit.h \
|
||||||
|
flash.h \
|
||||||
|
joyslider.h \
|
||||||
|
button_edit.h
|
||||||
|
|
||||||
joyslider.o: joyslider.cpp joyslider.h \
|
joyslider.o: joyslider.cpp joyslider.h \
|
||||||
constant.h
|
constant.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o joyslider.o joyslider.cpp
|
|
||||||
|
|
||||||
keycode.o: keycode.cpp keycode.h \
|
keycode.o: keycode.cpp keycode.h \
|
||||||
constant.h \
|
constant.h
|
||||||
getkey.h
|
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o keycode.o keycode.cpp
|
|
||||||
|
|
||||||
layout.o: layout.cpp layout.h \
|
layout.o: layout.cpp layout.h \
|
||||||
joypad.h \
|
joypad.h \
|
||||||
button.h \
|
|
||||||
keycode.h \
|
|
||||||
constant.h \
|
|
||||||
axis.h \
|
|
||||||
joypadw.h \
|
|
||||||
axisw.h \
|
|
||||||
flash.h \
|
|
||||||
axis_edit.h \
|
|
||||||
joyslider.h \
|
|
||||||
buttonw.h \
|
|
||||||
button_edit.h \
|
|
||||||
quickset.h \
|
|
||||||
error.h \
|
|
||||||
device.h \
|
|
||||||
trayicon/trayicon.h \
|
|
||||||
icon.h \
|
|
||||||
layout_edit.h
|
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o layout.o layout.cpp
|
|
||||||
|
|
||||||
layout_edit.o: layout_edit.cpp layout_edit.h \
|
|
||||||
flash.h \
|
|
||||||
layout.h \
|
|
||||||
joypad.h \
|
|
||||||
button.h \
|
|
||||||
keycode.h \
|
|
||||||
constant.h \
|
|
||||||
axis.h \
|
|
||||||
joypadw.h \
|
|
||||||
axisw.h \
|
|
||||||
axis_edit.h \
|
|
||||||
joyslider.h \
|
|
||||||
buttonw.h \
|
|
||||||
button_edit.h \
|
|
||||||
quickset.h \
|
|
||||||
error.h \
|
|
||||||
device.h \
|
|
||||||
trayicon/trayicon.h \
|
|
||||||
icon.h
|
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o layout_edit.o layout_edit.cpp
|
|
||||||
|
|
||||||
main.o: main.cpp layout.h \
|
|
||||||
joypad.h \
|
|
||||||
button.h \
|
|
||||||
keycode.h \
|
|
||||||
constant.h \
|
|
||||||
axis.h \
|
|
||||||
joypadw.h \
|
|
||||||
axisw.h \
|
|
||||||
flash.h \
|
|
||||||
axis_edit.h \
|
|
||||||
joyslider.h \
|
|
||||||
buttonw.h \
|
|
||||||
button_edit.h \
|
|
||||||
quickset.h \
|
|
||||||
error.h \
|
error.h \
|
||||||
device.h \
|
device.h \
|
||||||
trayicon/trayicon.h \
|
trayicon/trayicon.h \
|
||||||
icon.h \
|
icon.h \
|
||||||
layout_edit.h \
|
layout_edit.h \
|
||||||
event.h
|
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
|
|
||||||
|
|
||||||
quickset.o: quickset.cpp quickset.h \
|
|
||||||
joypad.h \
|
|
||||||
button.h \
|
button.h \
|
||||||
keycode.h \
|
|
||||||
constant.h \
|
|
||||||
axis.h \
|
axis.h \
|
||||||
joypadw.h \
|
joypadw.h \
|
||||||
|
component.h \
|
||||||
|
timer.h \
|
||||||
|
keycode.h \
|
||||||
|
event.h \
|
||||||
|
constant.h \
|
||||||
axisw.h \
|
axisw.h \
|
||||||
|
buttonw.h \
|
||||||
|
quickset.h \
|
||||||
|
axis_edit.h \
|
||||||
flash.h \
|
flash.h \
|
||||||
|
joyslider.h \
|
||||||
|
button_edit.h
|
||||||
|
|
||||||
|
layout_edit.o: layout_edit.cpp layout_edit.h \
|
||||||
|
flash.h \
|
||||||
|
layout.h \
|
||||||
|
device.h \
|
||||||
|
joypadw.h \
|
||||||
|
joypad.h \
|
||||||
|
error.h \
|
||||||
|
trayicon/trayicon.h \
|
||||||
|
icon.h \
|
||||||
|
button.h \
|
||||||
|
axis.h \
|
||||||
|
component.h \
|
||||||
|
timer.h \
|
||||||
|
keycode.h \
|
||||||
|
event.h \
|
||||||
|
constant.h \
|
||||||
|
axisw.h \
|
||||||
|
buttonw.h \
|
||||||
|
quickset.h \
|
||||||
axis_edit.h \
|
axis_edit.h \
|
||||||
joyslider.h \
|
joyslider.h \
|
||||||
buttonw.h \
|
button_edit.h
|
||||||
button_edit.h \
|
|
||||||
error.h \
|
|
||||||
getkey.h
|
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o quickset.o quickset.cpp
|
|
||||||
|
|
||||||
getkey.o: getkey.cpp getkey.h \
|
loop.o: loop.cpp loop.h \
|
||||||
constant.h
|
joypad.h \
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o getkey.o getkey.cpp
|
device.h \
|
||||||
|
button.h \
|
||||||
|
axis.h \
|
||||||
|
joypadw.h \
|
||||||
|
error.h \
|
||||||
|
component.h \
|
||||||
|
timer.h \
|
||||||
|
keycode.h \
|
||||||
|
event.h \
|
||||||
|
constant.h \
|
||||||
|
axisw.h \
|
||||||
|
buttonw.h \
|
||||||
|
quickset.h \
|
||||||
|
axis_edit.h \
|
||||||
|
flash.h \
|
||||||
|
joyslider.h \
|
||||||
|
button_edit.h
|
||||||
|
|
||||||
|
main.o: main.cpp loop.h \
|
||||||
|
layout.h \
|
||||||
|
event.h \
|
||||||
|
device.h \
|
||||||
|
error.h \
|
||||||
|
joypad.h \
|
||||||
|
button.h \
|
||||||
|
axis.h \
|
||||||
|
joypadw.h \
|
||||||
|
component.h \
|
||||||
|
timer.h \
|
||||||
|
keycode.h \
|
||||||
|
constant.h \
|
||||||
|
axisw.h \
|
||||||
|
buttonw.h \
|
||||||
|
quickset.h \
|
||||||
|
axis_edit.h \
|
||||||
|
flash.h \
|
||||||
|
joyslider.h \
|
||||||
|
button_edit.h \
|
||||||
|
trayicon/trayicon.h \
|
||||||
|
icon.h \
|
||||||
|
layout_edit.h
|
||||||
|
|
||||||
|
quickset.o: quickset.cpp quickset.h \
|
||||||
|
keycode.h \
|
||||||
|
joypad.h \
|
||||||
|
constant.h \
|
||||||
|
button.h \
|
||||||
|
axis.h \
|
||||||
|
joypadw.h \
|
||||||
|
error.h \
|
||||||
|
component.h \
|
||||||
|
timer.h \
|
||||||
|
event.h \
|
||||||
|
axisw.h \
|
||||||
|
buttonw.h \
|
||||||
|
axis_edit.h \
|
||||||
|
flash.h \
|
||||||
|
joyslider.h \
|
||||||
|
button_edit.h
|
||||||
|
|
||||||
trayicon.o: trayicon/trayicon.cpp trayicon/trayicon.h
|
trayicon.o: trayicon/trayicon.cpp trayicon/trayicon.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o trayicon.o trayicon/trayicon.cpp
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o trayicon.o trayicon/trayicon.cpp
|
||||||
@ -524,67 +410,116 @@ trayicon.o: trayicon/trayicon.cpp trayicon/trayicon.h
|
|||||||
trayicon_x11.o: trayicon/trayicon_x11.cpp trayicon/trayicon.h
|
trayicon_x11.o: trayicon/trayicon_x11.cpp trayicon/trayicon.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o trayicon_x11.o trayicon/trayicon_x11.cpp
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o trayicon_x11.o trayicon/trayicon_x11.cpp
|
||||||
|
|
||||||
moc_axis.o: moc_axis.cpp
|
moc_axis_edit.o: moc_axis_edit.cpp axis_edit.h joyslider.h \
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_axis.o moc_axis.cpp
|
keycode.h \
|
||||||
|
axis.h \
|
||||||
|
constant.h \
|
||||||
|
component.h \
|
||||||
|
timer.h \
|
||||||
|
event.h
|
||||||
|
|
||||||
moc_axis_edit.o: moc_axis_edit.cpp
|
moc_button_edit.o: moc_button_edit.cpp button_edit.h button.h \
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_axis_edit.o moc_axis_edit.cpp
|
keycode.h \
|
||||||
|
component.h \
|
||||||
|
timer.h \
|
||||||
|
event.h \
|
||||||
|
constant.h
|
||||||
|
|
||||||
moc_button.o: moc_button.cpp
|
moc_flash.o: moc_flash.cpp flash.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_button.o moc_button.cpp
|
|
||||||
|
|
||||||
moc_button_edit.o: moc_button_edit.cpp
|
moc_icon.o: moc_icon.cpp icon.h constant.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_button_edit.o moc_button_edit.cpp
|
|
||||||
|
|
||||||
moc_flash.o: moc_flash.cpp
|
moc_joypadw.o: moc_joypadw.cpp joypadw.h joypad.h \
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_flash.o moc_flash.cpp
|
axisw.h \
|
||||||
|
buttonw.h \
|
||||||
|
quickset.h \
|
||||||
|
button.h \
|
||||||
|
axis.h \
|
||||||
|
error.h \
|
||||||
|
component.h \
|
||||||
|
timer.h \
|
||||||
|
keycode.h \
|
||||||
|
event.h \
|
||||||
|
constant.h \
|
||||||
|
axis_edit.h \
|
||||||
|
flash.h \
|
||||||
|
joyslider.h \
|
||||||
|
button_edit.h
|
||||||
|
|
||||||
moc_icon.o: moc_icon.cpp
|
moc_keycode.o: moc_keycode.cpp keycode.h constant.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_icon.o moc_icon.cpp
|
|
||||||
|
|
||||||
moc_joypad.o: moc_joypad.cpp
|
moc_layout.o: moc_layout.cpp layout.h joypad.h \
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_joypad.o moc_joypad.cpp
|
error.h \
|
||||||
|
device.h \
|
||||||
|
trayicon/trayicon.h \
|
||||||
|
icon.h \
|
||||||
|
layout_edit.h \
|
||||||
|
button.h \
|
||||||
|
axis.h \
|
||||||
|
joypadw.h \
|
||||||
|
component.h \
|
||||||
|
timer.h \
|
||||||
|
keycode.h \
|
||||||
|
event.h \
|
||||||
|
constant.h \
|
||||||
|
axisw.h \
|
||||||
|
buttonw.h \
|
||||||
|
quickset.h \
|
||||||
|
axis_edit.h \
|
||||||
|
flash.h \
|
||||||
|
joyslider.h \
|
||||||
|
button_edit.h
|
||||||
|
|
||||||
moc_joypadw.o: moc_joypadw.cpp
|
moc_trayicon.o: trayicon/moc_trayicon.cpp trayicon/trayicon.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_joypadw.o moc_joypadw.cpp
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_trayicon.o trayicon/moc_trayicon.cpp
|
||||||
|
|
||||||
moc_keycode.o: moc_keycode.cpp
|
moc_axis_edit.cpp: $(MOC) axis_edit.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_keycode.o moc_keycode.cpp
|
$(MOC) axis_edit.h -o moc_axis_edit.cpp
|
||||||
|
|
||||||
moc_layout.o: moc_layout.cpp
|
moc_button_edit.cpp: $(MOC) button_edit.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_layout.o moc_layout.cpp
|
$(MOC) button_edit.h -o moc_button_edit.cpp
|
||||||
|
|
||||||
moc_getkey.o: moc_getkey.cpp
|
moc_flash.cpp: $(MOC) flash.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_getkey.o moc_getkey.cpp
|
$(MOC) flash.h -o moc_flash.cpp
|
||||||
|
|
||||||
moc_trayicon.o: moc_trayicon.cpp
|
moc_icon.cpp: $(MOC) icon.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_trayicon.o moc_trayicon.cpp
|
$(MOC) icon.h -o moc_icon.cpp
|
||||||
|
|
||||||
|
moc_joypadw.cpp: $(MOC) joypadw.h
|
||||||
|
$(MOC) joypadw.h -o moc_joypadw.cpp
|
||||||
|
|
||||||
|
moc_keycode.cpp: $(MOC) keycode.h
|
||||||
|
$(MOC) keycode.h -o moc_keycode.cpp
|
||||||
|
|
||||||
|
moc_layout.cpp: $(MOC) layout.h
|
||||||
|
$(MOC) layout.h -o moc_layout.cpp
|
||||||
|
|
||||||
|
trayicon/moc_trayicon.cpp: $(MOC) trayicon/trayicon.h
|
||||||
|
$(MOC) trayicon/trayicon.h -o trayicon/moc_trayicon.cpp
|
||||||
|
|
||||||
####### Install
|
####### Install
|
||||||
|
|
||||||
install_target: first FORCE
|
install_target: all
|
||||||
@$(CHK_DIR_EXISTS) $(INSTALL_ROOT)/bin/ || $(MKDIR) $(INSTALL_ROOT)/bin/
|
@$(CHK_DIR_EXISTS) "$(INSTALL_ROOT)/usr/bin/" || $(MKDIR) "$(INSTALL_ROOT)/usr/bin/"
|
||||||
-$(INSTALL_PROGRAM) "$(QMAKE_TARGET)" "$(INSTALL_ROOT)/bin/$(QMAKE_TARGET)"
|
-$(INSTALL_FILE) "$(QMAKE_TARGET)" "$(INSTALL_ROOT)/usr/bin/$(QMAKE_TARGET)"
|
||||||
-strip "$(INSTALL_ROOT)/bin/$(QMAKE_TARGET)"
|
-strip "$(INSTALL_ROOT)/usr/bin/$(QMAKE_TARGET)"
|
||||||
|
|
||||||
uninstall_target: FORCE
|
uninstall_target:
|
||||||
-$(DEL_FILE) "$(INSTALL_ROOT)/bin/$(QMAKE_TARGET)"
|
-$(DEL_FILE) "$(INSTALL_ROOT)/usr/bin/$(QMAKE_TARGET)"
|
||||||
-$(DEL_DIR) $(INSTALL_ROOT)/bin/
|
-$(DEL_DIR) "$(INSTALL_ROOT)/usr/bin/"
|
||||||
|
|
||||||
|
|
||||||
install_icons: first FORCE
|
install_icons: all
|
||||||
@$(CHK_DIR_EXISTS) $(INSTALL_ROOT)/share/pixmaps/qjoypad/ || $(MKDIR) $(INSTALL_ROOT)/share/pixmaps/qjoypad/
|
@$(CHK_DIR_EXISTS) "$(INSTALL_ROOT)/usr/share/pixmaps/qjoypad/" || $(MKDIR) "$(INSTALL_ROOT)/usr/share/pixmaps/qjoypad/"
|
||||||
cp ../icons/* /share/pixmaps/qjoypad; cd /share/pixmaps/qjoypad; ln -sf gamepad4-24x24.png icon24.png; ln -sf gamepad3-64x64.png icon64.png; chmod -R a+r /share/pixmaps/qjoypad
|
cp ../icons/* /usr/share/pixmaps/qjoypad; cd /usr/share/pixmaps/qjoypad; ln -sf gamepad4-24x24.png icon24.png; ln -sf gamepad3-64x64.png icon64.png; chmod -R a+r /usr/share/pixmaps/qjoypad
|
||||||
|
|
||||||
|
|
||||||
install_doc: first FORCE
|
install_doc: all
|
||||||
@$(CHK_DIR_EXISTS) $(INSTALL_ROOT)/doc/qjoypad3/ || $(MKDIR) $(INSTALL_ROOT)/doc/qjoypad3/
|
@$(CHK_DIR_EXISTS) "$(INSTALL_ROOT)/usr/doc/qjoypad3/" || $(MKDIR) "$(INSTALL_ROOT)/usr/doc/qjoypad3/"
|
||||||
cp ../README.txt ../LICENSE.txt /doc/qjoypad3
|
cp ../README.txt ../LICENSE.txt /usr/doc/qjoypad3
|
||||||
|
|
||||||
|
|
||||||
install: install_target install_icons install_doc FORCE
|
install: install_target install_icons install_doc
|
||||||
|
|
||||||
uninstall: uninstall_target FORCE
|
uninstall: uninstall_target
|
||||||
|
|
||||||
FORCE:
|
|
||||||
|
|
||||||
|
524
src/axis.cpp
524
src/axis.cpp
@ -1,208 +1,194 @@
|
|||||||
#include "axis.h"
|
#include "axis.h"
|
||||||
#include "event.h"
|
|
||||||
#define sqr(a) ((a)*(a))
|
#define sqr(a) ((a)*(a))
|
||||||
|
|
||||||
|
|
||||||
Axis::Axis( int i ) {
|
Axis::Axis( int i ) {
|
||||||
index = i;
|
index = i;
|
||||||
isOn = false;
|
isOn = false;
|
||||||
isDown = false;
|
//to keep toDefault from calling tossTimer without first calling takeTimer
|
||||||
state = 0;
|
gradient = false;
|
||||||
gradient = false;
|
toDefault();
|
||||||
toDefault();
|
|
||||||
tick = 0;
|
|
||||||
timer = new QTimer(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Axis::~Axis() {
|
Axis::~Axis() {
|
||||||
release();
|
release();
|
||||||
delete timer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Axis::read( QTextStream* stream ) {
|
bool Axis::read( QTextStream* stream ) {
|
||||||
// At this point, toDefault has just been called.
|
// At this point, toDefault has just been called.
|
||||||
|
|
||||||
//read in a line from the stream, and split it up into individual words
|
//read in a line from the stream, and split it up into individual words
|
||||||
QString input = stream->readLine().toLower();
|
QString input = stream->readLine().lower();
|
||||||
QRegExp regex("[\\s,]+");
|
QRegExp regex("[\\s,]+");
|
||||||
QStringList words = input.split(regex);
|
QStringList words = QStringList::split(regex,input);
|
||||||
|
|
||||||
//used to assure QString->int conversions worked
|
//used to assure QString->int conversions worked
|
||||||
bool ok;
|
bool ok;
|
||||||
//int to store values derived from strings
|
//int to store values derived from strings
|
||||||
int val;
|
int val;
|
||||||
|
|
||||||
//step through each word, check if it's a token we recognize
|
//step through each word, check if it's a token we recognize
|
||||||
for ( QStringList::Iterator it = words.begin(); it != words.end(); ++it ) {
|
for ( QStringList::Iterator it = words.begin(); it != words.end(); ++it ) {
|
||||||
if (*it == "maxspeed") {
|
if (*it == "maxspeed") {
|
||||||
++it; //move to the next word, which should be the maximum speed.
|
++it; //move to the next word, which should be the maximum speed.
|
||||||
//if no value was given, there's an error in the file, stop reading.
|
//if no value was given, there's an error in the file, stop reading.
|
||||||
if (it == words.end()) return false;
|
if (it == words.end()) return false;
|
||||||
//try to convert the value.
|
//try to convert the value.
|
||||||
val = (*it).toInt(&ok);
|
val = (*it).toInt(&ok);
|
||||||
//if that worked and the maximum speed is in range, set it.
|
//if that worked and the maximum speed is in range, set it.
|
||||||
if (ok && val >= 0 && val <= MAXMOUSESPEED) maxSpeed = val;
|
if (ok && val >= 0 && val <= MAXMOUSESPEED) maxSpeed = val;
|
||||||
//otherwise, faulty input, give up.
|
//otherwise, faulty input, give up.
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
//pretty much the same process for getting the dead zone
|
//pretty much the same process for getting the dead zone
|
||||||
else if (*it == "dzone") {
|
else if (*it == "dzone") {
|
||||||
++it;
|
++it;
|
||||||
if (it == words.end()) return false;
|
if (it == words.end()) return false;
|
||||||
val = (*it).toInt(&ok);
|
val = (*it).toInt(&ok);
|
||||||
if (ok && val >= 0 && val <= JOYMAX) dZone = val;
|
if (ok && val >= 0 && val <= JOYMAX) dZone = val;
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
//and again for the extreme zone,
|
//and again for the extreme zone,
|
||||||
else if (*it == "xzone") {
|
else if (*it == "xzone") {
|
||||||
++it;
|
++it;
|
||||||
if (it == words.end()) return false;
|
if (it == words.end()) return false;
|
||||||
val = (*it).toInt(&ok);
|
val = (*it).toInt(&ok);
|
||||||
if (ok && val >= 0 && val <= JOYMAX) xZone = val;
|
if (ok && val >= 0 && val <= JOYMAX) xZone = val;
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
//and for the positive keycode,
|
//and for the positive keycode,
|
||||||
else if (*it == "+key") {
|
else if (*it == "+key") {
|
||||||
++it;
|
++it;
|
||||||
if (it == words.end()) return false;
|
if (it == words.end()) return false;
|
||||||
val = (*it).toInt(&ok);
|
val = (*it).toInt(&ok);
|
||||||
if (ok && val >= 0 && val <= MAXKEY) pkeycode = val;
|
if (ok && val >= 0 && val <= MAXKEY) pkeycode = val;
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
//and finally for the negative keycode.
|
//and finally for the negative keycode.
|
||||||
else if (*it == "-key") {
|
else if (*it == "-key") {
|
||||||
++it;
|
++it;
|
||||||
if (it == words.end()) return false;
|
if (it == words.end()) return false;
|
||||||
val = (*it).toInt(&ok);
|
val = (*it).toInt(&ok);
|
||||||
if (ok && val >= 0 && val <= MAXKEY) nkeycode = val;
|
if (ok && val >= 0 && val <= MAXKEY) nkeycode = val;
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
//the rest of the options are keywords without integers
|
//the rest of the options are keywords without integers
|
||||||
else if (*it == "gradient") {
|
else if (*it == "gradient") {
|
||||||
gradient = true;
|
if (!gradient) takeTimer( this );
|
||||||
}
|
gradient = true;
|
||||||
else if (*it == "throttle+") {
|
}
|
||||||
throttle = 1;
|
else if (*it == "throttle+") {
|
||||||
}
|
throttle = 1;
|
||||||
else if (*it == "throttle-") {
|
}
|
||||||
throttle = -1;
|
else if (*it == "throttle-") {
|
||||||
}
|
throttle = -1;
|
||||||
else if (*it == "mouse+v") {
|
}
|
||||||
mode = mousepv;
|
else if (*it == "mouse+v") {
|
||||||
}
|
mode = mousepv;
|
||||||
else if (*it == "mouse-v") {
|
}
|
||||||
mode = mousenv;
|
else if (*it == "mouse-v") {
|
||||||
}
|
mode = mousenv;
|
||||||
else if (*it == "mouse+h") {
|
}
|
||||||
mode = mouseph;
|
else if (*it == "mouse+h") {
|
||||||
}
|
mode = mouseph;
|
||||||
else if (*it == "mouse-h") {
|
}
|
||||||
mode = mousenh;
|
else if (*it == "mouse-h") {
|
||||||
}
|
mode = mousenh;
|
||||||
//we ignore unrecognized words to be friendly and allow for additions to
|
}
|
||||||
//the format in later versions. Note, this means that typos will not get
|
//we ignore unrecognized words to be friendly and allow for additions to
|
||||||
//the desired effect OR produce an error message.
|
//the format in later versions. Note, this means that typos will not get
|
||||||
|
//the desired effect OR produce an error message.
|
||||||
}
|
}
|
||||||
|
|
||||||
//assume that xZone, dZone, or maxSpeed has changed, for simplicity.
|
//assume that xZone, dZone, or maxSpeed has changed, for simplicity.
|
||||||
//do a few floating point calculations.
|
//do a few floating point calculations.
|
||||||
adjustGradient();
|
adjustGradient();
|
||||||
|
|
||||||
//if we parsed through all of the words, yay! All done.
|
//if we parsed through all of the words, yay! All done.
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
void Axis::timerCalled() {
|
|
||||||
timerTick(++tick);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Axis::write( QTextStream* stream ) {
|
void Axis::write( QTextStream* stream ) {
|
||||||
*stream << "\t" << getName() << ": ";
|
*stream << "\t" << getName() << ": ";
|
||||||
if (gradient) *stream << "gradient, ";
|
if (gradient) *stream << "gradient, ";
|
||||||
if (throttle > 0) *stream << "throttle+, ";
|
if (throttle > 0) *stream << "throttle+, ";
|
||||||
else if (throttle < 0) *stream << "throttle-, ";
|
else if (throttle < 0) *stream << "throttle-, ";
|
||||||
if (dZone != DZONE) *stream << "dZone " << dZone << ", ";
|
if (dZone != DZONE) *stream << "dZone " << dZone << ", ";
|
||||||
if (xZone != XZONE) *stream << "xZone " << xZone << ", ";
|
if (xZone != XZONE) *stream << "xZone " << xZone << ", ";
|
||||||
if (mode == keybd) {
|
if (mode == keybd) {
|
||||||
*stream << "+key " << pkeycode << ", "
|
*stream << "+key " << pkeycode << ", "
|
||||||
<< "-key " << nkeycode << "\n";
|
<< "-key " << nkeycode << "\n";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (gradient) *stream << "maxSpeed " << maxSpeed << ", ";
|
if (gradient) *stream << "maxSpeed " << maxSpeed << ", ";
|
||||||
*stream << "mouse";
|
*stream << "mouse";
|
||||||
if (mode == mousepv)
|
if (mode == mousepv)
|
||||||
*stream << "+v\n";
|
*stream << "+v\n";
|
||||||
else if (mode == mousenv)
|
else if (mode == mousenv)
|
||||||
*stream << "-v\n";
|
*stream << "-v\n";
|
||||||
else if (mode == mouseph)
|
else if (mode == mouseph)
|
||||||
*stream << "+h\n";
|
*stream << "+h\n";
|
||||||
else if (mode == mousenh)
|
else if (mode == mousenh)
|
||||||
*stream << "-h\n";
|
*stream << "-h\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Axis::release() {
|
void Axis::release() {
|
||||||
//if we're pressing a key, let it go.
|
//if we're pressing a key, let it go.
|
||||||
if (isDown) {
|
if (isDown) {
|
||||||
move(false);
|
move(false);
|
||||||
isDown = false;
|
isDown = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Axis::jsevent( int value ) {
|
void Axis::jsevent( int value ) {
|
||||||
//adjust real value to throttle value
|
//adjust real value to throttle value
|
||||||
if (throttle == 0)
|
if (throttle == 0)
|
||||||
state = value;
|
state = value;
|
||||||
else if (throttle == -1)
|
else if (throttle == -1)
|
||||||
state = (value + JOYMIN) / 2;
|
state = (value + JOYMIN) / 2;
|
||||||
else
|
else
|
||||||
state = (value + JOYMAX) / 2;
|
state = (value + JOYMAX) / 2;
|
||||||
|
|
||||||
//set isOn, deal with state changing.
|
//set isOn, deal with state changing.
|
||||||
//if was on but now should be off:
|
//if was on but now should be off:
|
||||||
if (isOn && abs(state) <= dZone) {
|
if (isOn && abs(state) <= dZone) {
|
||||||
isOn = false;
|
isOn = false;
|
||||||
if (gradient) {
|
if (gradient) release();
|
||||||
release();
|
}
|
||||||
timer->stop();
|
//if was off but now should be on:
|
||||||
tick = 0;
|
else if (!isOn && abs(state) >= dZone) {
|
||||||
}
|
isOn = true;
|
||||||
}
|
if (gradient) duration = (abs(state) * FREQ) / JOYMAX;
|
||||||
//if was off but now should be on:
|
}
|
||||||
else if (!isOn && abs(state) >= dZone) {
|
//otherwise, state doesn't change! Don't touch it.
|
||||||
isOn = true;
|
else return;
|
||||||
if (gradient) {
|
|
||||||
duration = (abs(state) * FREQ) / JOYMAX;
|
|
||||||
connect(timer, SIGNAL(timeout()), this, SLOT(timerCalled()));
|
|
||||||
timer->start(MSEC);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//otherwise, state doesn't change! Don't touch it.
|
|
||||||
else return;
|
|
||||||
|
|
||||||
//gradient will trigger movement on its own via timer().
|
//gradient will trigger movement on its own via timer().
|
||||||
//non-gradient needs to be told to move.
|
//non-gradient needs to be told to move.
|
||||||
if (!gradient) {
|
if (!gradient) {
|
||||||
move(isOn);
|
move(isOn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Axis::toDefault() {
|
void Axis::toDefault() {
|
||||||
release();
|
release();
|
||||||
gradient = false;
|
|
||||||
throttle = 0;
|
if (gradient) tossTimer( this );
|
||||||
maxSpeed = 100;
|
gradient = false;
|
||||||
dZone = DZONE;
|
throttle = 0;
|
||||||
tick = 0;
|
maxSpeed = 100;
|
||||||
xZone = XZONE;
|
dZone = DZONE;
|
||||||
mode = keybd;
|
xZone = XZONE;
|
||||||
pkeycode = 0;
|
mode = keybd;
|
||||||
nkeycode = 0;
|
pkeycode = 0;
|
||||||
downkey = 0;
|
nkeycode = 0;
|
||||||
state = 0;
|
downkey = 0;
|
||||||
adjustGradient();
|
state = 0;
|
||||||
|
adjustGradient();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Axis::isDefault() {
|
bool Axis::isDefault() {
|
||||||
@ -217,119 +203,119 @@ bool Axis::isDefault() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Axis::inDeadZone( int val ) {
|
bool Axis::inDeadZone( int val ) {
|
||||||
int value;
|
int value;
|
||||||
if (throttle == 0)
|
if (throttle == 0)
|
||||||
value = val;
|
value = val;
|
||||||
else if (throttle == -1)
|
else if (throttle == -1)
|
||||||
value = (val + JOYMIN) / 2;
|
value = (val + JOYMIN) / 2;
|
||||||
else
|
else
|
||||||
value = (val + JOYMAX) / 2;
|
value = (val + JOYMAX) / 2;
|
||||||
return (abs(value) < dZone);
|
return (abs(value) < dZone);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Axis::status() {
|
QString Axis::status() {
|
||||||
QString result = getName() + " : [";
|
QString result = getName() + " : [";
|
||||||
if (mode == keybd) {
|
if (mode == keybd) {
|
||||||
if (throttle == 0)
|
if (throttle == 0)
|
||||||
result += "KEYBOARD";
|
result += "KEYBOARD";
|
||||||
else result += "THROTTLE";
|
else result += "THROTTLE";
|
||||||
}
|
}
|
||||||
else result += "MOUSE";
|
else result += "MOUSE";
|
||||||
return result + "]";
|
return result + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Axis::setKey(bool positive, int value) {
|
void Axis::setKey(bool positive, int value) {
|
||||||
if (positive)
|
if (positive)
|
||||||
pkeycode = value;
|
pkeycode = value;
|
||||||
else
|
else
|
||||||
nkeycode = value;
|
nkeycode = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Axis::timerTick( int tick ) {
|
void Axis::timer( int tick ) {
|
||||||
if (isOn) {
|
if (isOn) {
|
||||||
if (mode == keybd) {
|
if (mode == keybd) {
|
||||||
if (tick % FREQ == 0) {
|
if (tick % FREQ == 0) {
|
||||||
if (duration == FREQ) {
|
if (duration == FREQ) {
|
||||||
if (!isDown) move(true);
|
if (!isDown) move(true);
|
||||||
duration = (abs(state) * FREQ) / JOYMAX;
|
duration = (abs(state) * FREQ) / JOYMAX;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
move(true);
|
move(true);
|
||||||
}
|
}
|
||||||
if (tick % FREQ == duration) {
|
if (tick % FREQ == duration) {
|
||||||
move(false);
|
move(false);
|
||||||
duration = (abs(state) * FREQ) / JOYMAX;
|
duration = (abs(state) * FREQ) / JOYMAX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
move(true);
|
move(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Axis::adjustGradient() {
|
void Axis::adjustGradient() {
|
||||||
//create a nice quadratic curve fitting it to the points
|
//create a nice quadratic curve fitting it to the points
|
||||||
//(dZone,0) and (xZone,MaxSpeed)
|
//(dZone,0) and (xZone,MaxSpeed)
|
||||||
a = (double) (maxSpeed) / sqr(xZone - dZone);
|
a = (double) (maxSpeed) / sqr(xZone - dZone);
|
||||||
b = -2 * a * dZone;
|
b = -2 * a * dZone;
|
||||||
c = a * sqr(dZone);
|
c = a * sqr(dZone);
|
||||||
//actual equation for curve is: y = ax^2 + b
|
//actual equation for curve is: y = ax^2 + b
|
||||||
//where x is the state of the axis and y is the distance the mouse should move.
|
//where x is the state of the axis and y is the distance the mouse should move.
|
||||||
}
|
}
|
||||||
|
|
||||||
void Axis::move( bool press ) {
|
void Axis::move( bool press ) {
|
||||||
xevent e;
|
xevent e;
|
||||||
if (mode == keybd) {
|
if (mode == keybd) {
|
||||||
//prevent KeyPress-KeyPress and KeyRelease-KeyRelease pairs.
|
//prevent KeyPress-KeyPress and KeyRelease-KeyRelease pairs.
|
||||||
//this would only happen in odd circumstances involving the setup
|
//this would only happen in odd circumstances involving the setup
|
||||||
//dialog being open and blocking events from happening.
|
//dialog being open and blocking events from happening.
|
||||||
if (isDown == press) return;
|
if (isDown == press) return;
|
||||||
isDown = press;
|
isDown = press;
|
||||||
if (press) {
|
if (press) {
|
||||||
e.type = KPRESS;
|
e.type = KPRESS;
|
||||||
downkey = (state > 0)?pkeycode:nkeycode;
|
downkey = (state > 0)?pkeycode:nkeycode;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
e.type = KREL;
|
e.type = KREL;
|
||||||
}
|
}
|
||||||
e.value1 = downkey;
|
e.value1 = downkey;
|
||||||
e.value2 = 0;
|
e.value2 = 0;
|
||||||
}
|
}
|
||||||
//if using the mouse
|
//if using the mouse
|
||||||
else if (press) {
|
else if (press){
|
||||||
int dist;
|
int dist;
|
||||||
if (gradient) {
|
if (gradient) {
|
||||||
//calculate our mouse speed curve based on calculations made in
|
//calculate our mouse speed curve based on calculations made in
|
||||||
//adjustGradient()
|
//adjustGradient()
|
||||||
int absState = abs(state);
|
int absState = abs(state);
|
||||||
if (absState >= xZone) dist = maxSpeed;
|
if (absState >= xZone) dist = maxSpeed;
|
||||||
else if (absState <= dZone) dist = 0;
|
else if (absState <= dZone) dist = 0;
|
||||||
else dist = (int) (a*sqr(absState) + b*absState + c);
|
else dist = (int) (a*sqr(absState) + b*absState + c);
|
||||||
}
|
}
|
||||||
//if not gradient, always go full speed.
|
//if not gradient, always go full speed.
|
||||||
else dist = maxSpeed;
|
else dist = maxSpeed;
|
||||||
|
|
||||||
//if we're on the negative side of the axis, must compensate for
|
//if we're on the negative side of the axis, must compensate for
|
||||||
//squaring and make distance negative.
|
//squaring and make distance negative.
|
||||||
if (state < 0) dist = -dist;
|
if (state < 0) dist = -dist;
|
||||||
e.type = WARP;
|
e.type = WARP;
|
||||||
if (mode == mousepv) {
|
if (mode == mousepv) {
|
||||||
e.value1 = 0;
|
e.value1 = 0;
|
||||||
e.value2 = dist;
|
e.value2 = dist;
|
||||||
}
|
}
|
||||||
else if (mode == mousenv) {
|
else if (mode == mousenv) {
|
||||||
e.value1 = 0;
|
e.value1 = 0;
|
||||||
e.value2 = -dist;
|
e.value2 = -dist;
|
||||||
}
|
}
|
||||||
else if (mode == mouseph) {
|
else if (mode == mouseph) {
|
||||||
e.value1 = dist;
|
e.value1 = dist;
|
||||||
e.value2 = 0;
|
e.value2 = 0;
|
||||||
}
|
}
|
||||||
else if (mode == mousenh) {
|
else if (mode == mousenh) {
|
||||||
e.value1 = -dist;
|
e.value1 = -dist;
|
||||||
e.value2 = 0;
|
e.value2 = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//actually create the event
|
//actually create the event
|
||||||
sendevent(e);
|
sendevent(e);
|
||||||
}
|
}
|
||||||
|
23
src/axis.h
23
src/axis.h
@ -4,11 +4,11 @@
|
|||||||
//abs()
|
//abs()
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <QTimer>
|
//parent of Axis
|
||||||
#include <QTextStream>
|
#include "component.h"
|
||||||
#include <QRegExp>
|
|
||||||
#include <QStringList>
|
//to request a periodic tap on the shoulder for gradient mode
|
||||||
#include "constant.h"
|
#include "timer.h"
|
||||||
|
|
||||||
//default and arbitrary values for dZone and xZone
|
//default and arbitrary values for dZone and xZone
|
||||||
#define DZONE 3000
|
#define DZONE 3000
|
||||||
@ -18,9 +18,8 @@
|
|||||||
enum AxisMode {keybd, mousepv, mousenv, mouseph, mousenh};
|
enum AxisMode {keybd, mousepv, mousenv, mouseph, mousenh};
|
||||||
|
|
||||||
//represents one joystick axis
|
//represents one joystick axis
|
||||||
class Axis : public QObject {
|
class Axis : public Component {
|
||||||
Q_OBJECT
|
//so AxisEdit can manipulate fields directly.
|
||||||
//so AxisEdit can manipulate fields directly.
|
|
||||||
friend class AxisEdit;
|
friend class AxisEdit;
|
||||||
public:
|
public:
|
||||||
Axis( int i );
|
Axis( int i );
|
||||||
@ -46,13 +45,12 @@ class Axis : public QObject {
|
|||||||
void setKey(bool positive, int value);
|
void setKey(bool positive, int value);
|
||||||
//happens every MSEC milliseconds (constant.h)
|
//happens every MSEC milliseconds (constant.h)
|
||||||
//uses tick to decide if key events should be generated
|
//uses tick to decide if key events should be generated
|
||||||
void timerTick( int tick );
|
void timer( int tick );
|
||||||
//recalculates the gradient curve. This should be run every time
|
//recalculates the gradient curve. This should be run every time
|
||||||
//maxSpeed, xZone, or dZone are changed.
|
//maxSpeed, xZone, or dZone are changed.
|
||||||
void adjustGradient();
|
void adjustGradient();
|
||||||
protected:
|
protected:
|
||||||
int tick;
|
//This axis is logically depressed (positive or negative)
|
||||||
//This axis is logically depressed (positive or negative)
|
|
||||||
//if the axis is gradient, this is true even if it is not
|
//if the axis is gradient, this is true even if it is not
|
||||||
//currently generating a keypress at the instant.
|
//currently generating a keypress at the instant.
|
||||||
bool isOn;
|
bool isOn;
|
||||||
@ -86,9 +84,6 @@ class Axis : public QObject {
|
|||||||
//note, the key is still clicked at the same pace no matter what,
|
//note, the key is still clicked at the same pace no matter what,
|
||||||
//this just decides how long it stays down each cycle.
|
//this just decides how long it stays down each cycle.
|
||||||
int duration;
|
int duration;
|
||||||
QTimer *timer;
|
|
||||||
public slots:
|
|
||||||
void timerCalled();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,150 +1,131 @@
|
|||||||
#include "axis_edit.h"
|
#include "axis_edit.h"
|
||||||
|
|
||||||
|
|
||||||
AxisEdit::AxisEdit( Axis* ax )
|
AxisEdit::AxisEdit( Axis* ax )
|
||||||
:QDialog() {
|
:QDialog() {
|
||||||
//build the dialog, display current axis settings :)
|
//build the dialog, display current axis settings :)
|
||||||
axis = ax;
|
axis = ax;
|
||||||
setWindowTitle("Set " + axis->getName());
|
setCaption("Set " + axis->getName());
|
||||||
setWindowIcon(QPixmap(ICON24));
|
setIcon(QPixmap(ICON24));
|
||||||
|
|
||||||
//h, v, and v2 are all references to layouts. They are used to refer to
|
//h, v, and v2 are all references to layouts. They are used to refer to
|
||||||
//various layouts as the dialog is built and are not pointing to the same
|
//various layouts as the dialog is built and are not pointing to the same
|
||||||
//thing throughout. This is just because I don't care about the layouts
|
//thing throughout. This is just because I don't care about the layouts
|
||||||
//after I have placed the widgets within them and there's no reasno to
|
//after I have placed the widgets within them and there's no reasno to
|
||||||
//keep track of them.
|
//keep track of them.
|
||||||
|
|
||||||
QVBoxLayout* v = new QVBoxLayout(this);
|
QVBoxLayout* v = new QVBoxLayout(this, 5, 5);
|
||||||
v->setMargin(5);
|
|
||||||
v->setSpacing(5);
|
|
||||||
|
|
||||||
QHBoxLayout* h = new QHBoxLayout();
|
QHBoxLayout* h = new QHBoxLayout();
|
||||||
QVBoxLayout* v2 = new QVBoxLayout();
|
QVBoxLayout* v2 = new QVBoxLayout(0,5,5);
|
||||||
v2->setMargin(5);
|
CGradient = new QCheckBox("Gradient", this);
|
||||||
v2->setSpacing(5);
|
CGradient->setChecked(axis->gradient);
|
||||||
CGradient = new QCheckBox("Gradient", this);
|
v2->addWidget(CGradient);
|
||||||
CGradient->setChecked(axis->gradient);
|
|
||||||
v2->addWidget(CGradient);
|
|
||||||
|
|
||||||
CMode = new QComboBox(this);
|
CMode = new QComboBox(this);
|
||||||
CMode->insertItem((int)keybd, QString("Keyboard"), QVariant(NULL));
|
CMode->insertItem("Keyboard",keybd);
|
||||||
CMode->insertItem((int) mousepv,QString("Mouse (Vert.)"),QVariant(NULL));
|
CMode->insertItem("Mouse (Vert.)",mousepv);
|
||||||
CMode->insertItem((int) mousenv, QString("Mouse (Vert. Rev.)"), QVariant(NULL));
|
CMode->insertItem("Mouse (Vert. Rev.)", mousenv);
|
||||||
CMode->insertItem((int) mouseph, "Mouse (Hor.)", QVariant(NULL));
|
CMode->insertItem("Mouse (Hor.)", mouseph);
|
||||||
CMode->insertItem((int)mousenh, QString("Mouse (Hor. Rev.)"), NULL);
|
CMode->insertItem("Mouse (Hor. Rev.)", mousenh);
|
||||||
CMode->setCurrentIndex( axis->mode );
|
CMode->setCurrentItem( axis->mode );
|
||||||
connect(CMode, SIGNAL(activated(int)), this, SLOT( CModeChanged( int )));
|
connect(CMode, SIGNAL(activated(int)), this, SLOT( CModeChanged( int )));
|
||||||
v2->addWidget(CMode);
|
v2->addWidget(CMode);
|
||||||
h->addLayout(v2);
|
h->addLayout(v2);
|
||||||
|
|
||||||
MouseBox = new QFrame(this);
|
MouseBox = new QFrame(this);
|
||||||
MouseBox->setFrameStyle( QFrame::Box | QFrame::Sunken );
|
MouseBox->setFrameStyle( QFrame::Box | QFrame::Sunken );
|
||||||
v2 = new QVBoxLayout(MouseBox);
|
v2 = new QVBoxLayout(MouseBox,5,5);
|
||||||
v2->setSpacing(5);
|
v2->setAutoAdd(true);
|
||||||
v2->setMargin(5);
|
new QLabel("Mouse Speed", MouseBox);
|
||||||
//v2->setAutoAdd(true);
|
SSpeed = new QSpinBox(0,MAXMOUSESPEED,1,MouseBox);
|
||||||
QLabel *mouseLabel = new QLabel("Mouse Speed", MouseBox);
|
SSpeed->setValue(axis->maxSpeed);
|
||||||
v2->addWidget(mouseLabel);
|
h->addWidget(MouseBox);
|
||||||
SSpeed = new QSpinBox(MouseBox);
|
v->addLayout(h);
|
||||||
SSpeed->setRange(0,MAXMOUSESPEED);
|
|
||||||
SSpeed->setSingleStep(1);
|
|
||||||
SSpeed->setValue(axis->maxSpeed);
|
|
||||||
v2->addWidget(SSpeed);
|
|
||||||
h->addWidget(MouseBox);
|
|
||||||
v->addLayout(h);
|
|
||||||
|
|
||||||
Slider = new JoySlider(axis->dZone, axis->xZone, axis->state, this);
|
Slider = new JoySlider(axis->dZone, axis->xZone, axis->state, this);
|
||||||
v->addWidget(Slider);
|
v->addWidget(Slider);
|
||||||
|
|
||||||
KeyBox = new QFrame(this);
|
KeyBox = new QFrame(this);
|
||||||
KeyBox->setFrameStyle( QFrame::Box | QFrame::Sunken );
|
KeyBox->setFrameStyle( QFrame::Box | QFrame::Sunken );
|
||||||
h = new QHBoxLayout(KeyBox);
|
h = new QHBoxLayout(KeyBox, 5, 5);
|
||||||
h->setSpacing(5);
|
h->setAutoAdd(true);
|
||||||
h->setMargin(5);
|
BNeg = new KeyButton(axis->getName(),axis->nkeycode,KeyBox);
|
||||||
//h->setAutoAdd(true);
|
|
||||||
BNeg = new KeyButton(axis->getName(),axis->nkeycode,KeyBox);
|
|
||||||
|
|
||||||
CThrottle = new QComboBox(KeyBox);
|
CThrottle = new QComboBox(KeyBox);
|
||||||
CThrottle->insertItem(0,"Neg. Throttle",QVariant(NULL));
|
CThrottle->insertItem("Neg. Throttle",0);
|
||||||
CThrottle->insertItem(1,"No Throttle",QVariant(NULL));
|
CThrottle->insertItem("No Throttle",1);
|
||||||
CThrottle->insertItem(2,"Pos. Throttle",QVariant(NULL));
|
CThrottle->insertItem("Pos. Throttle",2);
|
||||||
CThrottle->setCurrentIndex(axis->throttle + 1);
|
CThrottle->setCurrentItem(axis->throttle + 1);
|
||||||
connect( CThrottle, SIGNAL( activated( int )), this, SLOT( CThrottleChanged( int )));
|
connect( CThrottle, SIGNAL( activated( int )), this, SLOT( CThrottleChanged( int )));
|
||||||
|
|
||||||
BPos = new KeyButton(axis->getName(),axis->pkeycode,KeyBox);
|
BPos = new KeyButton(axis->getName(),axis->pkeycode,KeyBox);
|
||||||
h->addWidget(BNeg);
|
v->addWidget( KeyBox );
|
||||||
h->addWidget(CThrottle);
|
|
||||||
h->addWidget(BPos);
|
|
||||||
v->addWidget( KeyBox );
|
|
||||||
|
|
||||||
h = new QHBoxLayout();
|
h = new QHBoxLayout();
|
||||||
BOkay = new QPushButton("Okay", this);
|
BOkay = new QPushButton("Okay", this);
|
||||||
connect(BOkay, SIGNAL( clicked() ), this, SLOT( accept()));
|
connect(BOkay, SIGNAL( clicked() ), this, SLOT( accept()));
|
||||||
h->addWidget(BOkay);
|
h->addWidget(BOkay);
|
||||||
BCancel = new QPushButton("Cancel", this);
|
BCancel = new QPushButton("Cancel", this);
|
||||||
connect(BCancel, SIGNAL( clicked() ), this, SLOT( reject()));
|
connect(BCancel, SIGNAL( clicked() ), this, SLOT( reject()));
|
||||||
h->addWidget(BCancel);
|
h->addWidget(BCancel);
|
||||||
v->addLayout(h);
|
v->addLayout(h);
|
||||||
|
|
||||||
CModeChanged( axis->mode );
|
CModeChanged( axis->mode );
|
||||||
CThrottleChanged( axis->throttle + 1 );
|
CThrottleChanged( axis->throttle + 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void AxisEdit::show() {
|
void AxisEdit::show() {
|
||||||
QDialog::show();
|
QDialog::show();
|
||||||
setFixedSize(size());
|
setFixedSize(size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AxisEdit::setState( int val ) {
|
void AxisEdit::setState( int val ) {
|
||||||
Slider->setValue( val );
|
Slider->setValue( val );
|
||||||
}
|
}
|
||||||
|
|
||||||
void AxisEdit::CModeChanged( int index ) {
|
void AxisEdit::CModeChanged( int index ) {
|
||||||
if (index == keybd) {
|
if (index == keybd) {
|
||||||
MouseBox->setEnabled(false);
|
MouseBox->setEnabled(false);
|
||||||
KeyBox->setEnabled(true);
|
KeyBox->setEnabled(true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
MouseBox->setEnabled(true);
|
MouseBox->setEnabled(true);
|
||||||
KeyBox->setEnabled(false);
|
KeyBox->setEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AxisEdit::CThrottleChanged( int index ) {
|
void AxisEdit::CThrottleChanged( int index ) {
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case 0:
|
case 0: BNeg->setEnabled(true);
|
||||||
BNeg->setEnabled(true);
|
BPos->setEnabled(false);
|
||||||
BPos->setEnabled(false);
|
break;
|
||||||
break;
|
case 1: BNeg->setEnabled(true);
|
||||||
case 1:
|
BPos->setEnabled(true);
|
||||||
BNeg->setEnabled(true);
|
break;
|
||||||
BPos->setEnabled(true);
|
case 2: BNeg->setEnabled(false);
|
||||||
break;
|
BPos->setEnabled(true);
|
||||||
case 2:
|
break;
|
||||||
BNeg->setEnabled(false);
|
}
|
||||||
BPos->setEnabled(true);
|
Slider->setThrottle( index - 1 );
|
||||||
break;
|
|
||||||
}
|
|
||||||
Slider->setThrottle( index - 1 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AxisEdit::accept() {
|
void AxisEdit::accept() {
|
||||||
//if the gradient status has changed, either request a timer or turn it down.
|
//if the gradient status has changed, either request a timer or turn it down.
|
||||||
/*if (axis->gradient) {
|
if (axis->gradient) {
|
||||||
if (!CGradient->isChecked()) tossTimer(axis);
|
if (!CGradient->isChecked()) tossTimer(axis);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (CGradient->isChecked()) takeTimer(axis);
|
if (CGradient->isChecked()) takeTimer(axis);
|
||||||
}*/
|
}
|
||||||
axis->gradient = CGradient->isChecked();
|
axis->gradient = CGradient->isChecked();
|
||||||
axis->maxSpeed = SSpeed->value();
|
axis->maxSpeed = SSpeed->value();
|
||||||
axis->throttle = CThrottle->currentIndex() - 1;
|
axis->throttle = CThrottle->currentItem() - 1;
|
||||||
axis->dZone = Slider->dZone();
|
axis->dZone = Slider->dZone();
|
||||||
axis->xZone = Slider->xZone();
|
axis->xZone = Slider->xZone();
|
||||||
axis->mode = (AxisMode) CMode->currentIndex();
|
axis->mode = (AxisMode) CMode->currentItem();
|
||||||
axis->pkeycode = BPos->getValue();
|
axis->pkeycode = BPos->getValue();
|
||||||
axis->nkeycode = BNeg->getValue();
|
axis->nkeycode = BNeg->getValue();
|
||||||
axis->adjustGradient();
|
axis->adjustGradient();
|
||||||
|
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,22 @@
|
|||||||
#ifndef AXIS_EDIT_H
|
#ifndef AXIS_EDIT_H
|
||||||
#define AXIS_EDIT_H
|
#define AXIS_EDIT_H
|
||||||
//to refer to the axis we're editing
|
|
||||||
//for building up the dialog we need
|
//for building up the dialog we need
|
||||||
#include "axis.h"
|
#include <qdialog.h>
|
||||||
#include <QComboBox>
|
#include <qcheckbox.h>
|
||||||
#include <QSpinBox>
|
#include <qcombobox.h>
|
||||||
#include <QCheckBox>
|
#include <qframe.h>
|
||||||
#include <QLabel>
|
#include <qspinbox.h>
|
||||||
|
#include <qlayout.h>
|
||||||
|
#include <qlabel.h>
|
||||||
|
|
||||||
//for my home-brewed widgets
|
//for my home-brewed widgets
|
||||||
#include "joyslider.h"
|
#include "joyslider.h"
|
||||||
#include "keycode.h"
|
#include "keycode.h"
|
||||||
|
|
||||||
|
//to refer to the axis we're editing
|
||||||
|
#include "axis.h"
|
||||||
|
|
||||||
class AxisEdit : public QDialog {
|
class AxisEdit : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -1,38 +1,37 @@
|
|||||||
#include "axisw.h"
|
#include "axisw.h"
|
||||||
|
|
||||||
|
|
||||||
AxisWidget::AxisWidget( Axis* a, QWidget* parent )
|
AxisWidget::AxisWidget( Axis* a, QWidget* parent )
|
||||||
: FlashButton( "",parent) {
|
: FlashButton( "",parent) {
|
||||||
axis = a;
|
axis = a;
|
||||||
ae = NULL;
|
ae = NULL;
|
||||||
update();
|
update();
|
||||||
on = false;
|
on = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AxisWidget::jsevent( int val ) {
|
void AxisWidget::jsevent( int val ) {
|
||||||
bool newOn = !axis->inDeadZone(val);
|
bool newOn = !axis->inDeadZone(val);
|
||||||
if (on != newOn) {
|
if (on != newOn) {
|
||||||
on = newOn;
|
on = newOn;
|
||||||
flash();
|
flash();
|
||||||
}
|
}
|
||||||
if (ae != NULL) ae->setState(val);
|
if (ae != NULL) ae->setState(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AxisWidget::update() {
|
void AxisWidget::update() {
|
||||||
setText( axis->status());
|
setText( axis->status());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AxisWidget::mouseReleaseEvent( QMouseEvent* e ) {
|
void AxisWidget::mouseReleaseEvent( QMouseEvent* e ) {
|
||||||
//create the edit dialog,
|
//create the edit dialog,
|
||||||
ae = new AxisEdit(axis);
|
ae = new AxisEdit(axis);
|
||||||
//get its input
|
//get its input
|
||||||
ae->exec();
|
ae->exec();
|
||||||
//now that it's done, destroy it!
|
//now that it's done, destroy it!
|
||||||
delete ae;
|
delete ae;
|
||||||
//and remember that it's gone.
|
//and remember that it's gone.
|
||||||
ae = NULL;
|
ae = NULL;
|
||||||
update();
|
update();
|
||||||
//release the button. Waiting to do this until the very end has the nice
|
//release the button. Waiting to do this until the very end has the nice
|
||||||
//effect of keeping the button depressed while the dialog is shown.
|
//effect of keeping the button depressed while the dialog is shown.
|
||||||
FlashButton::mouseReleaseEvent( e );
|
FlashButton::mouseReleaseEvent( e );
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
#ifndef AXIS_WIDGET_H
|
#ifndef AXIS_WIDGET_H
|
||||||
#define AXIS_WIDGET_H
|
#define AXIS_WIDGET_H
|
||||||
|
|
||||||
#include <QMouseEvent>
|
|
||||||
//so we can interact with the axis this refers to
|
//so we can interact with the axis this refers to
|
||||||
#include "axis.h"
|
#include "axis.h"
|
||||||
//for the FlashButton widget
|
|
||||||
#include "flash.h"
|
|
||||||
|
|
||||||
//so we can edit this axis when the user clicks the button
|
//so we can edit this axis when the user clicks the button
|
||||||
#include "axis_edit.h"
|
#include "axis_edit.h"
|
||||||
|
//for the FlashButton widget
|
||||||
|
#include "flash.h"
|
||||||
|
|
||||||
class AxisWidget : public FlashButton {
|
class AxisWidget : public FlashButton {
|
||||||
public:
|
public:
|
||||||
|
248
src/button.cpp
248
src/button.cpp
@ -1,178 +1,156 @@
|
|||||||
#include "button.h"
|
#include "button.h"
|
||||||
#include "event.h"
|
|
||||||
|
|
||||||
Button::Button( int i ) {
|
Button::Button( int i ) {
|
||||||
index = i;
|
index = i;
|
||||||
isButtonPressed = false;
|
isOn = false;
|
||||||
isDown = false;
|
//to keep toDefault from calling tossTimer without first calling takeTimer
|
||||||
rapidfire = false;
|
rapidfire = false;
|
||||||
timer = new QTimer(this);
|
toDefault();
|
||||||
toDefault();
|
|
||||||
tick = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Button::~Button() {
|
Button::~Button() {
|
||||||
release();
|
release();
|
||||||
//delete timer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Button::read( QTextStream* stream ) {
|
bool Button::read( QTextStream* stream ) {
|
||||||
// at this point, toDefault() has just been called.
|
// at this point, toDefault() has just been called.
|
||||||
|
|
||||||
//read in a line of text and break it into words
|
//read in a line of text and break it into words
|
||||||
QString input = stream->readLine().toLower();
|
QString input = stream->readLine().lower();
|
||||||
QRegExp regex("[\\s,]+");
|
QRegExp regex("[\\s,]+");
|
||||||
QStringList words = input.split(regex);
|
QStringList words = QStringList::split(regex,input);
|
||||||
|
|
||||||
//used to assure correct conversion of QStrings -> ints
|
//used to assure correct conversion of QStrings -> ints
|
||||||
bool ok;
|
bool ok;
|
||||||
//used to receive converted ints from QStrings.
|
//used to receive converted ints from QStrings.
|
||||||
int val;
|
int val;
|
||||||
|
|
||||||
//go through every word on the line describing this button.
|
//go through every word on the line describing this button.
|
||||||
for ( QStringList::Iterator it = words.begin(); it != words.end(); ++it ) {
|
for ( QStringList::Iterator it = words.begin(); it != words.end(); ++it ) {
|
||||||
if (*it == "mouse") {
|
if (*it == "mouse") {
|
||||||
++it;
|
++it;
|
||||||
if (it == words.end()) return false;
|
if (it == words.end()) return false;
|
||||||
val = (*it).toInt(&ok);
|
val = (*it).toInt(&ok);
|
||||||
if (ok && val >= 0 && val <= MAXKEY) {
|
if (ok && val >= 0 && val <= MAXKEY) {
|
||||||
useMouse = true;
|
useMouse = true;
|
||||||
mousecode = val;
|
mousecode = val;
|
||||||
}
|
}
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
else if (*it == "key") {
|
else if (*it == "key") {
|
||||||
++it;
|
++it;
|
||||||
if (it == words.end()) return false;
|
if (it == words.end()) return false;
|
||||||
val = (*it).toInt(&ok);
|
val = (*it).toInt(&ok);
|
||||||
if (ok && val >= 0 && val <= MAXKEY) {
|
if (ok && val >= 0 && val <= MAXKEY) {
|
||||||
useMouse = false;
|
useMouse = false;
|
||||||
keycode = val;
|
keycode = val;
|
||||||
}
|
}
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
else if (*it == "rapidfire") {
|
else if (*it == "rapidfire") {
|
||||||
rapidfire = true;
|
if (rapidfire == false) takeTimer( this );
|
||||||
}
|
rapidfire = true;
|
||||||
else if (*it == "sticky") {
|
}
|
||||||
sticky = true;
|
else if (*it == "sticky") {
|
||||||
}
|
sticky = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::write( QTextStream* stream ) {
|
void Button::write( QTextStream* stream ) {
|
||||||
*stream << "\t" << getName() << ": ";
|
*stream << "\t" << getName() << ": ";
|
||||||
if (rapidfire) *stream << "rapidfire, ";
|
if (rapidfire) *stream << "rapidfire, ";
|
||||||
if (sticky) *stream << "sticky, ";
|
if (sticky) *stream << "sticky, ";
|
||||||
*stream << (useMouse?"mouse ":"key ") << (useMouse?mousecode:keycode) << "\n";
|
*stream << (useMouse?"mouse ":"key ") << (useMouse?mousecode:keycode) << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::release() {
|
void Button::release() {
|
||||||
if (isDown) {
|
if (isDown) {
|
||||||
click(false);
|
click(false);
|
||||||
isDown = true;
|
isDown = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::jsevent( int value ) {
|
void Button::jsevent( int value ) {
|
||||||
bool newval = (value == 1);
|
bool newval = (value == 1);
|
||||||
if (sticky) {
|
if (sticky) {
|
||||||
//the state of a sticky key only changes on button press, not button release.
|
//the state of a sticky key only changes on button press, not button release.
|
||||||
if (value == 1) {
|
if (newval) isOn = !isOn;
|
||||||
isButtonPressed = !isButtonPressed;
|
else return;
|
||||||
}
|
}
|
||||||
else return;
|
//if the received event indicates a change in state,
|
||||||
}
|
else if (newval != isOn) {
|
||||||
//if the received event indicates a change in state,
|
isOn = newval; //change state
|
||||||
else if (newval != isButtonPressed) {
|
}
|
||||||
isButtonPressed = newval; //change state
|
//otherwise... we don't care. This shouldn't happen.
|
||||||
if (isButtonPressed && rapidfire) {
|
else return;
|
||||||
tick = 0;
|
//if rapidfire is on, then timer() will do its job. Otherwise we must
|
||||||
connect(timer, SIGNAL(timeout()), this, SLOT(timerCalled()));
|
//manually triger the key event.
|
||||||
timer->start(MSEC);
|
if (!rapidfire) click(isOn);
|
||||||
}
|
|
||||||
if (!isButtonPressed && rapidfire) {
|
|
||||||
timer->stop();
|
|
||||||
if(isDown) {
|
|
||||||
click(false);
|
|
||||||
}
|
|
||||||
tick = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//otherwise... we don't care. This shouldn't happen.
|
|
||||||
else return;
|
|
||||||
//if rapidfire is on, then timer() will do its job. Otherwise we must
|
|
||||||
//manually triger the key event.
|
|
||||||
if (!rapidfire) {
|
|
||||||
click(isButtonPressed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::toDefault() {
|
void Button::toDefault() {
|
||||||
rapidfire = false;
|
if (rapidfire == true) tossTimer( this );
|
||||||
sticky = false;
|
rapidfire = false;
|
||||||
useMouse = false;
|
sticky = false;
|
||||||
keycode = 0;
|
useMouse = false;
|
||||||
mousecode = 0;
|
keycode = 0;
|
||||||
timer->stop();
|
mousecode = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Button::isDefault() {
|
bool Button::isDefault() {
|
||||||
return (rapidfire == false) &&
|
return (rapidfire == false) &&
|
||||||
(sticky == false) &&
|
(sticky == false) &&
|
||||||
(useMouse == false) &&
|
(useMouse == false) &&
|
||||||
(keycode == 0) &&
|
(keycode == 0) &&
|
||||||
(mousecode == 0);
|
(mousecode == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Button::status() {
|
QString Button::status() {
|
||||||
if (useMouse) {
|
if (useMouse) {
|
||||||
return getName() + " : Mouse " + QString::number(mousecode);
|
return getName() + " : Mouse " + QString::number(mousecode);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return getName() + " : " + QString(ktos(keycode));
|
return getName() + " : " + QString(ktos(keycode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::setKey( bool mouse, int value ) {
|
void Button::setKey( bool mouse, int value ) {
|
||||||
if (mouse) {
|
if (mouse) {
|
||||||
mousecode = value;
|
mousecode = value;
|
||||||
useMouse = true;
|
useMouse = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
keycode = value;
|
keycode = value;
|
||||||
useMouse = false;
|
useMouse = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::timerTick( int tick ) {
|
void Button::timer( int tick ) {
|
||||||
if (isButtonPressed) {
|
if (isOn) {
|
||||||
//originally I just clicked true and then false right after, but this
|
//originally I just clicked true and then false right after, but this
|
||||||
//was not recognized by some programs. I need a delay in between.
|
//was not recognized by some programs. I need a delay in between.
|
||||||
if (tick % FREQ == 0) {
|
if (tick % FREQ == 0) {
|
||||||
click(true);
|
click(true);
|
||||||
}
|
}
|
||||||
if (tick % FREQ == FREQ / 2) {
|
if (tick % FREQ == FREQ / 2) {
|
||||||
click(false);
|
click(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::click( bool press ) {
|
void Button::click( bool press ) {
|
||||||
if (isDown == press) return;
|
if (isDown == press) return;
|
||||||
isDown = press;
|
isDown = press;
|
||||||
xevent click;
|
xevent click;
|
||||||
//determine which of the four possible events we're sending.
|
//determine which of the four possible events we're sending.
|
||||||
if (press) click.type = useMouse?BPRESS:KPRESS;
|
if (press) click.type = useMouse?BPRESS:KPRESS;
|
||||||
else click.type = useMouse?BREL:KREL;
|
else click.type = useMouse?BREL:KREL;
|
||||||
//set up the event,
|
//set up the event,
|
||||||
click.value1 = useMouse?mousecode:keycode;
|
click.value1 = useMouse?mousecode:keycode;
|
||||||
click.value2 = 0;
|
click.value2 = 0;
|
||||||
//and send it.
|
//and send it.
|
||||||
sendevent( click );
|
sendevent( click );
|
||||||
}
|
|
||||||
|
|
||||||
void Button::timerCalled() {
|
|
||||||
timerTick(++tick);
|
|
||||||
}
|
}
|
||||||
|
20
src/button.h
20
src/button.h
@ -1,18 +1,19 @@
|
|||||||
#ifndef BUTTON_H
|
#ifndef BUTTON_H
|
||||||
#define BUTTON_H
|
#define BUTTON_H
|
||||||
|
|
||||||
#include <QTimer>
|
//parent of Button
|
||||||
#include <QTextStream>
|
#include "component.h"
|
||||||
|
|
||||||
|
//to request a periodic tap on the shoulder for rapidfire
|
||||||
|
#include "timer.h"
|
||||||
|
|
||||||
//for getting a key name in status()
|
//for getting a key name in status()
|
||||||
#include "keycode.h"
|
#include "keycode.h"
|
||||||
|
|
||||||
//note that the Button class, unlike the axis class, does not need a release
|
//note that the Button class, unlike the axis class, does not need a release
|
||||||
//function because it releases the key as soon as it is pressed.
|
//function because it releases the key as soon as it is pressed.
|
||||||
class Button : public QObject {
|
class Button : public Component {
|
||||||
Q_OBJECT
|
friend class ButtonEdit;
|
||||||
friend class ButtonEdit;
|
|
||||||
public:
|
public:
|
||||||
Button( int i );
|
Button( int i );
|
||||||
~Button();
|
~Button();
|
||||||
@ -35,26 +36,23 @@ class Button : public QObject {
|
|||||||
//set the key code for this axis. Used by quickset.
|
//set the key code for this axis. Used by quickset.
|
||||||
void setKey(bool mouse, int value);
|
void setKey(bool mouse, int value);
|
||||||
//happens every MSEC (constant.h) milliseconds
|
//happens every MSEC (constant.h) milliseconds
|
||||||
void timerTick( int tick );
|
void timer( int tick );
|
||||||
protected:
|
protected:
|
||||||
//true iff this button is physically depressed.
|
//true iff this button is physically depressed.
|
||||||
bool isButtonPressed;
|
bool isOn;
|
||||||
//the index of this button on the joystick
|
//the index of this button on the joystick
|
||||||
int index;
|
int index;
|
||||||
//actually sends a key press/release
|
//actually sends a key press/release
|
||||||
virtual void click( bool press );
|
virtual void click( bool press );
|
||||||
//is a simulated key currently depressed?
|
//is a simulated key currently depressed?
|
||||||
bool isDown;
|
bool isDown;
|
||||||
int tick;
|
|
||||||
//button settings
|
//button settings
|
||||||
bool rapidfire;
|
bool rapidfire;
|
||||||
bool sticky;
|
bool sticky;
|
||||||
bool useMouse;
|
bool useMouse;
|
||||||
int keycode;
|
int keycode;
|
||||||
int mousecode; //like keycode, only mousebutton ;)
|
int mousecode; //like keycode, only mousebutton ;)
|
||||||
QTimer *timer;
|
|
||||||
public slots:
|
|
||||||
void timerCalled();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,66 +1,60 @@
|
|||||||
#include "button_edit.h"
|
#include "button_edit.h"
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
|
|
||||||
ButtonEdit::ButtonEdit(Button* butt)
|
ButtonEdit::ButtonEdit(Button* butt)
|
||||||
:QDialog(0) {
|
:QDialog(0,0,true) {
|
||||||
setModal(true);
|
//build the dialog!
|
||||||
//build the dialog!
|
button = butt;
|
||||||
button = butt;
|
setCaption("Set " + button->getName());
|
||||||
setWindowTitle("Set " + button->getName());
|
setIcon(QPixmap(ICON24));
|
||||||
setWindowIcon(QPixmap(ICON24));
|
|
||||||
|
|
||||||
QVBoxLayout* v = new QVBoxLayout(this);
|
QVBoxLayout* v = new QVBoxLayout(this, 5, 5);
|
||||||
v->setMargin(5);
|
|
||||||
v->setSpacing(5);
|
|
||||||
|
|
||||||
BKKey = new KeyButton( button->getName(), button->useMouse?button->mousecode:button->keycode, this, true, button->useMouse);
|
BKKey = new KeyButton( button->getName(), button->useMouse?button->mousecode:button->keycode, this, true, button->useMouse);
|
||||||
v->addWidget(BKKey);
|
v->addWidget(BKKey);
|
||||||
|
|
||||||
QHBoxLayout* h = new QHBoxLayout();
|
QHBoxLayout* h = new QHBoxLayout();
|
||||||
CSticky = new QCheckBox("Sticky", this);
|
CSticky = new QCheckBox("Sticky", this);
|
||||||
CSticky->setChecked(button->sticky);
|
CSticky->setChecked(button->sticky);
|
||||||
h->addWidget(CSticky);
|
h->addWidget(CSticky);
|
||||||
CRapid = new QCheckBox("Rapid Fire", this);
|
CRapid = new QCheckBox("Rapid Fire", this);
|
||||||
CRapid->setChecked(button->rapidfire);
|
CRapid->setChecked(button->rapidfire);
|
||||||
h->addWidget(CRapid);
|
h->addWidget(CRapid);
|
||||||
v->addLayout(h);
|
v->addLayout(h);
|
||||||
|
|
||||||
h = new QHBoxLayout();
|
h = new QHBoxLayout();
|
||||||
BOkay = new QPushButton("Okay", this);
|
BOkay = new QPushButton("Okay", this);
|
||||||
connect(BOkay, SIGNAL( clicked() ), this, SLOT( accept()));
|
connect(BOkay, SIGNAL( clicked() ), this, SLOT( accept()));
|
||||||
h->addWidget(BOkay);
|
h->addWidget(BOkay);
|
||||||
BCancel = new QPushButton("Cancel", this);
|
BCancel = new QPushButton("Cancel", this);
|
||||||
connect(BCancel, SIGNAL( clicked() ), this, SLOT( reject()));
|
connect(BCancel, SIGNAL( clicked() ), this, SLOT( reject()));
|
||||||
h->addWidget(BCancel);
|
h->addWidget(BCancel);
|
||||||
v->addLayout(h);
|
v->addLayout(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonEdit::show() {
|
void ButtonEdit::show() {
|
||||||
QDialog::show();
|
QDialog::show();
|
||||||
setFixedSize(size());
|
setFixedSize(size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonEdit::accept() {
|
void ButtonEdit::accept() {
|
||||||
//if the rapidfire status has changed, either request a timer or turn it down.
|
//if the rapidfire status has changed, either request a timer or turn it down.
|
||||||
/*if (button->rapidfire) {
|
if (button->rapidfire) {
|
||||||
if (!CRapid->isChecked()) tossTimer(button);
|
if (!CRapid->isChecked()) tossTimer(button);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (CRapid->isChecked()) takeTimer(button);
|
if (CRapid->isChecked()) takeTimer(button);
|
||||||
}*/
|
}
|
||||||
button->rapidfire = CRapid->isChecked();
|
button->rapidfire = CRapid->isChecked();
|
||||||
button->sticky = (CSticky->isChecked());
|
button->sticky = (CSticky->isChecked());
|
||||||
//if the user chose a mouse button...
|
//if the user chose a mouse button...
|
||||||
if (BKKey->choseMouse()) {
|
if (BKKey->choseMouse()) {
|
||||||
button->useMouse = true;
|
button->useMouse = true;
|
||||||
button->mousecode = BKKey->getValue();
|
button->mousecode = BKKey->getValue();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
button->useMouse = false;
|
button->useMouse = false;
|
||||||
button->keycode = BKKey->getValue();
|
button->keycode = BKKey->getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
#ifndef BUTTON_EDIT_H
|
#ifndef BUTTON_EDIT_H
|
||||||
#define BUTTON_EDIT_H
|
#define BUTTON_EDIT_H
|
||||||
|
|
||||||
#include <QPushButton>
|
//used to build the dialog:
|
||||||
#include <QCheckBox>
|
#include <qdialog.h>
|
||||||
|
#include <qpushbutton.h>
|
||||||
|
#include <qcheckbox.h>
|
||||||
|
#include <qlayout.h>
|
||||||
|
|
||||||
//we need to edit a Button
|
//we need to edit a Button
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
|
|
||||||
|
|
||||||
//to get a new key for the button.
|
//to get a new key for the button.
|
||||||
#include "keycode.h"
|
#include "keycode.h"
|
||||||
|
|
||||||
|
@ -1,30 +1,29 @@
|
|||||||
#include "buttonw.h"
|
#include "buttonw.h"
|
||||||
|
|
||||||
|
|
||||||
ButtonWidget::ButtonWidget( Button* b, QWidget* parent )
|
ButtonWidget::ButtonWidget( Button* b, QWidget* parent )
|
||||||
: FlashButton( "", parent) {
|
: FlashButton( "", parent) {
|
||||||
button = b;
|
button = b;
|
||||||
update();
|
update();
|
||||||
on = false;
|
on = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonWidget::jsevent( int val ) {
|
void ButtonWidget::jsevent( int val ) {
|
||||||
bool newOn = (val == 1);
|
bool newOn = (val == 1);
|
||||||
if (on != newOn) {
|
if (on != newOn) {
|
||||||
on = newOn;
|
on = newOn;
|
||||||
flash();
|
flash();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonWidget::update() {
|
void ButtonWidget::update() {
|
||||||
setText( button->status());
|
setText( button->status());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonWidget::mouseReleaseEvent( QMouseEvent* e ) {
|
void ButtonWidget::mouseReleaseEvent( QMouseEvent* e ) {
|
||||||
ButtonEdit* be = new ButtonEdit(button);
|
ButtonEdit* be = new ButtonEdit(button);
|
||||||
be->exec();
|
be->exec();
|
||||||
delete be;
|
delete be;
|
||||||
|
|
||||||
update();
|
update();
|
||||||
FlashButton::mouseReleaseEvent( e );
|
FlashButton::mouseReleaseEvent( e );
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,6 @@
|
|||||||
#include "button_edit.h"
|
#include "button_edit.h"
|
||||||
//this IS a FlashButton
|
//this IS a FlashButton
|
||||||
#include "flash.h"
|
#include "flash.h"
|
||||||
#ifdef Bool
|
|
||||||
#undef Bool
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <QMouseEvent>
|
|
||||||
|
|
||||||
class ButtonWidget : public FlashButton {
|
class ButtonWidget : public FlashButton {
|
||||||
public:
|
public:
|
||||||
|
36
src/component.h
Normal file
36
src/component.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#ifndef COMPONENT_H
|
||||||
|
#define COMPONENT_H
|
||||||
|
|
||||||
|
|
||||||
|
//for parsing data from a file
|
||||||
|
#include <qstringlist.h>
|
||||||
|
#include <qtextstream.h>
|
||||||
|
#include <qregexp.h>
|
||||||
|
|
||||||
|
//parent of Component
|
||||||
|
#include <qobject.h>
|
||||||
|
|
||||||
|
#include "event.h"
|
||||||
|
#include "constant.h"
|
||||||
|
|
||||||
|
|
||||||
|
//just a general blanket class to cover Button and Axis
|
||||||
|
//it is completely worthless in itself.
|
||||||
|
class Component : public QObject {
|
||||||
|
public:
|
||||||
|
virtual bool read( QTextStream* ) {return true; };
|
||||||
|
virtual void write( QTextStream* ) {};
|
||||||
|
virtual void release() {};
|
||||||
|
virtual void jsevent( int ) {};
|
||||||
|
virtual void toDefault() {};
|
||||||
|
virtual bool isDefault() { return true; };
|
||||||
|
virtual QString getName() { return ""; };
|
||||||
|
virtual QString status() { return ""; };
|
||||||
|
virtual void timer( int ) {};
|
||||||
|
protected:
|
||||||
|
bool isOn;
|
||||||
|
bool isDown;
|
||||||
|
int index;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -24,6 +24,4 @@
|
|||||||
|
|
||||||
#define NAME "QJoyPad 3.4"
|
#define NAME "QJoyPad 3.4"
|
||||||
|
|
||||||
#define MOUSE_OFFSET 400
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
#ifndef JOY_DEVICE_H
|
#ifndef JOY_DEVICE_H
|
||||||
#define JOY_DEVICE_H
|
#define JOY_DEVICE_H
|
||||||
|
|
||||||
|
#include <qintdict.h>
|
||||||
#include "joypad.h"
|
#include "joypad.h"
|
||||||
|
|
||||||
//the purpose of this file is to make device information available to what
|
//the purpose of this file is to make device information available to what
|
||||||
//needs it.
|
//needs it.
|
||||||
|
|
||||||
//a collection of joysticks currently available on this computer
|
//a collection of joysticks currently available on this computer
|
||||||
extern QHash<int, JoyPad*> available;
|
extern QIntDict<JoyPad> available;
|
||||||
|
|
||||||
//a collection of joypad objects representing all the available joysticks
|
//a collection of joypad objects representing all the available joysticks
|
||||||
//as well as the ones defined in a layout buy not currently plugged in.
|
//as well as the ones defined in a layout buy not currently plugged in.
|
||||||
extern QHash<int, JoyPad*> joypads;
|
extern QIntDict<JoyPad> joypads;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
static void error(QString type, QString message ) {
|
static void error(QString type, QString message ) {
|
||||||
QMessageBox::warning(0,NAME" - " + type,
|
QMessageBox::warning(0,NAME" - " + type,
|
||||||
message, QMessageBox::Ok, Qt::NoButton);
|
message, QMessageBox::Ok, QMessageBox::NoButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -5,17 +5,17 @@ Display* display;
|
|||||||
|
|
||||||
//actually creates an XWindows event :)
|
//actually creates an XWindows event :)
|
||||||
void sendevent( xevent e ) {
|
void sendevent( xevent e ) {
|
||||||
if (e.value1 == 0 && e.value2 == 0) return;
|
if (e.value1 == 0 && e.value2 == 0) return;
|
||||||
if (e.type == WARP) {
|
if (e.type == WARP) {
|
||||||
XTestFakeRelativeMotionEvent(display, e.value1, e.value2, 0);
|
XTestFakeRelativeMotionEvent(display, e.value1, e.value2, 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (e.type == KREL || e.type == KPRESS) {
|
if (e.type == KREL || e.type == KPRESS) {
|
||||||
XTestFakeKeyEvent(display, e.value1, (e.type == KPRESS), 0);
|
XTestFakeKeyEvent(display, e.value1, (e.type == KPRESS), 0);
|
||||||
}
|
}
|
||||||
else if (e.type == BREL || e.type == BPRESS) {
|
else if (e.type == BREL | e.type == BPRESS) {
|
||||||
XTestFakeButtonEvent(display, e.value1, (e.type == BPRESS), 0);
|
XTestFakeButtonEvent(display, e.value1, (e.type == BPRESS), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
XFlush(display);
|
XFlush(display);
|
||||||
}
|
}
|
||||||
|
130
src/flash.cpp
130
src/flash.cpp
@ -1,99 +1,97 @@
|
|||||||
#include "flash.h"
|
#include "flash.h"
|
||||||
//Added by qt3to4:
|
|
||||||
|
|
||||||
//Modified here (and in .h) to not have default arguments for 2 and 3.
|
//Modified here (and in .h) to not have default arguments for 2 and 3.
|
||||||
//This caused an error with a development version of g++ on a Mandrake system
|
//This caused an error with a development version of g++ on a Mandrake system
|
||||||
//in Sweden.
|
//in Sweden.
|
||||||
FlashButton::FlashButton( QString text, QWidget* parent, QString name )
|
FlashButton::FlashButton( QString text, QWidget* parent, QString name )
|
||||||
:QPushButton( text, parent )
|
:QPushButton( text, parent, name )
|
||||||
{
|
{
|
||||||
this->setObjectName(name);
|
//record the base palette for posterity.
|
||||||
//record the base palette for posterity.
|
Normal = palette();
|
||||||
Normal = palette();
|
|
||||||
|
|
||||||
//define the palette the button will have when it flashes.
|
//define the palette the button will have when it flashes.
|
||||||
QPalette cg = this->palette();
|
QColorGroup cg = this->palette().inactive();
|
||||||
cg.setCurrentColorGroup(QPalette::Inactive);
|
cg.setColor(QColorGroup::Button, HIGHLIGHT);
|
||||||
cg.setColor(QPalette::Button, HIGHLIGHT);
|
cg.setColor(QColorGroup::Light, HIGHLIGHT.light(150));
|
||||||
cg.setColor(QPalette::Light, HIGHLIGHT.light(150));
|
cg.setColor(QColorGroup::Midlight, HIGHLIGHT.light(125));
|
||||||
cg.setColor(QPalette::Midlight, HIGHLIGHT.light(125));
|
cg.setColor(QColorGroup::Dark, HIGHLIGHT.dark(200));
|
||||||
cg.setColor(QPalette::Dark, HIGHLIGHT.dark(200));
|
cg.setColor(QColorGroup::Mid, HIGHLIGHT.dark(150));
|
||||||
cg.setColor(QPalette::Mid, HIGHLIGHT.dark(150));
|
Flash = QPalette(cg,cg,cg);
|
||||||
Flash = cg;
|
isflash=false;
|
||||||
isflash=false;
|
|
||||||
|
|
||||||
setAutoDefault( false );
|
|
||||||
setFocusPolicy(Qt::NoFocus);
|
|
||||||
|
|
||||||
|
setAutoDefault( false );
|
||||||
|
setFocusPolicy(QWidget::NoFocus);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlashButton::flash()
|
void FlashButton::flash()
|
||||||
{
|
{
|
||||||
emit( flashed( !isflash ) );
|
emit( flashed( !isflash ) );
|
||||||
if (isflash)
|
if (isflash)
|
||||||
{
|
{
|
||||||
setPalette( Normal );
|
setPalette( Normal );
|
||||||
isflash = false;
|
isflash = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setPalette( Flash );
|
setPalette( Flash );
|
||||||
isflash = true;
|
isflash = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FlashRadioArray::FlashRadioArray( int count, QString names[], bool horizontal, QWidget* parent)
|
FlashRadioArray::FlashRadioArray( int count, QString names[], bool horizontal, QWidget* parent)
|
||||||
:QWidget( parent )
|
:QWidget( parent )
|
||||||
{
|
{
|
||||||
if (horizontal) {
|
if (horizontal)
|
||||||
LMain = new QHBoxLayout( this);
|
LMain = new QHBoxLayout( this, 5, 5 );
|
||||||
LMain->setMargin(5);
|
else
|
||||||
LMain->setSpacing(5);
|
LMain = new QVBoxLayout( this, 5, 5 );
|
||||||
} else {
|
LMain->setAutoAdd( true );
|
||||||
LMain = new QVBoxLayout( this);
|
|
||||||
LMain->setMargin(5);
|
|
||||||
LMain->setSpacing(5);
|
|
||||||
}
|
|
||||||
|
|
||||||
Buttons = new FlashButton*[count];
|
Buttons = new FlashButton*[count];
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
Buttons[i] = new FlashButton( names[i], this, "" );
|
Buttons[i] = new FlashButton( names[i], this, "" );
|
||||||
//when any of the buttons is clicked, it calls the same function on this.
|
//when any of the buttons is clicked, it calls the same function on this.
|
||||||
connect( Buttons[i], SIGNAL( clicked() ), this, SLOT( clicked() ));
|
connect( Buttons[i], SIGNAL( clicked() ), this, SLOT( clicked() ));
|
||||||
LMain->addWidget(Buttons[i]);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Count = count;
|
Count = count;
|
||||||
State = 0;
|
State = 0;
|
||||||
Buttons[0]->setDown( true );
|
Buttons[0]->setDown( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
int FlashRadioArray::getState()
|
int FlashRadioArray::getState()
|
||||||
{
|
{
|
||||||
return State;
|
return State;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlashRadioArray::flash( int index )
|
void FlashRadioArray::flash( int index )
|
||||||
{
|
{
|
||||||
Buttons[index]->flash();
|
Buttons[index]->flash();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlashRadioArray::clicked()
|
void FlashRadioArray::clicked()
|
||||||
{
|
{
|
||||||
//go through each button. If it wasn't the button that was just clicked,
|
//go through each button. If it wasn't the button that was just clicked,
|
||||||
//then make sure that it is up. If it WAS the button that was clicked,
|
//then make sure that it is up. If it WAS the button that was clicked,
|
||||||
//remember that index as the new state.
|
//remember that index as the new state.
|
||||||
for (int i = 0; i < Count; i++)
|
for (int i = 0; i < Count; i++)
|
||||||
{
|
{
|
||||||
if ( Buttons[i] != sender() )
|
if ( Buttons[i] != sender() )
|
||||||
Buttons[i]->setDown( false );
|
Buttons[i]->setDown( false );
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
State = i;
|
State = i;
|
||||||
Buttons[i]->setDown( true );
|
Buttons[i]->setDown( true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
emit changed( State );
|
emit changed( State );
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <QPushButton>
|
#include <qpushbutton.h>
|
||||||
#include <QPalette>
|
#include <qlayout.h>
|
||||||
#include <QBoxLayout>
|
|
||||||
|
|
||||||
|
|
||||||
//A QPushButton that can flash a color
|
//A QPushButton that can flash a color
|
||||||
|
41
src/icon.cpp
41
src/icon.cpp
@ -1,33 +1,30 @@
|
|||||||
#include "icon.h"
|
#include "icon.h"
|
||||||
|
|
||||||
|
#include <qpopupmenu.h>
|
||||||
|
|
||||||
FloatingIcon::FloatingIcon( const QPixmap &icon, QMenu *popup, QWidget *parent, const char *name)
|
FloatingIcon::FloatingIcon( const QPixmap &icon, QPopupMenu *popup, QWidget *parent, const char *name)
|
||||||
: QDialog( parent ) {
|
: QDialog( parent, name ) {
|
||||||
this->setObjectName(name);
|
setCaption(NAME);
|
||||||
setWindowTitle(NAME);
|
setPaletteBackgroundPixmap(icon);
|
||||||
QPalette palette;
|
pop = popup;
|
||||||
palette.setBrush(backgroundRole(), QBrush(icon));
|
|
||||||
setPalette(palette);
|
|
||||||
//setPaletteBackgroundPixmap(icon);
|
|
||||||
pop = popup;
|
|
||||||
|
|
||||||
setFixedSize(64,64);
|
setFixedSize(64,64);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FloatingIcon::mousePressEvent( QMouseEvent* e ) {
|
void FloatingIcon::mousePressEvent( QMouseEvent* e ) {
|
||||||
//if it was the right mouse button,
|
//if it was the right mouse button,
|
||||||
if (e->button() == Qt::RightButton) {
|
if (e->button() == RightButton) {
|
||||||
//bring up the popup menu.
|
//bring up the popup menu.
|
||||||
pop->popup( e->globalPos() );
|
pop->popup( e->globalPos() );
|
||||||
e->accept();
|
e->accept();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//otherwise, treat it as a regular click.
|
//otherwise, treat it as a regular click.
|
||||||
emit clicked();
|
emit clicked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FloatingIcon::closeEvent( QCloseEvent* e ) {
|
void FloatingIcon::closeEvent( QCloseEvent* e ) {
|
||||||
emit closed();
|
emit closed();
|
||||||
e->accept();
|
e->accept();
|
||||||
}
|
}
|
||||||
|
16
src/icon.h
16
src/icon.h
@ -1,25 +1,27 @@
|
|||||||
#ifndef JOY_ICON_H
|
#ifndef JOY_ICON_H
|
||||||
#define JOY_ICON_H
|
#define JOY_ICON_H
|
||||||
|
|
||||||
#include <QDialog>
|
//for creating a floating icon in notray mode :)
|
||||||
#include <QMenu>
|
#include <qdialog.h>
|
||||||
#include <QPixmap>
|
//the pixmap to load
|
||||||
#include <QMouseEvent>
|
#include <qpixmap.h>
|
||||||
#include <QCloseEvent>
|
|
||||||
|
|
||||||
#include "constant.h"
|
#include "constant.h"
|
||||||
|
|
||||||
|
//A quirk in QT forbids me from simply including qpopupmenu.h
|
||||||
|
class QPopupMenu;
|
||||||
|
|
||||||
class FloatingIcon : public QDialog {
|
class FloatingIcon : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
FloatingIcon( const QPixmap &icon, QMenu *popup = 0, QWidget *parent = 0, const char *name = 0);
|
FloatingIcon( const QPixmap &icon, QPopupMenu *popup = 0, QWidget *parent = 0, const char *name = 0);
|
||||||
signals:
|
signals:
|
||||||
void closed();
|
void closed();
|
||||||
void clicked();
|
void clicked();
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent( QMouseEvent* e );
|
void mousePressEvent( QMouseEvent* e );
|
||||||
void closeEvent( QCloseEvent* e );
|
void closeEvent( QCloseEvent* e );
|
||||||
QMenu* pop;
|
QPopupMenu* pop;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
375
src/joypad.cpp
375
src/joypad.cpp
@ -1,270 +1,175 @@
|
|||||||
#include "unistd.h"
|
|
||||||
#include "joypad.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <poll.h>
|
|
||||||
#include <QApplication>
|
|
||||||
JoyPad::JoyPad( int i, int dev ) {
|
|
||||||
//remember the index,
|
|
||||||
index = i;
|
|
||||||
|
|
||||||
//load data from the joystick device, if available.
|
#include "joypad.h"
|
||||||
joydevFileHandle = NULL;
|
JoyPad::JoyPad( int i, int dev ) {
|
||||||
if(dev > 0) {
|
//remember the index,
|
||||||
resetToDev(dev);
|
index = i;
|
||||||
joydevFileHandle = new QSocketNotifier(dev, QSocketNotifier::Read, this);
|
|
||||||
connect(joydevFileHandle, SIGNAL(activated(int)), this, SLOT(handleJoyEvents(int)));
|
//load data from the joystick device, if available.
|
||||||
}
|
resetToDev(dev);
|
||||||
//there is no JoyPadWidget yet.
|
|
||||||
jpw = NULL;
|
//there is no JoyPadWidget yet.
|
||||||
|
jpw = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoyPad::resetToDev(int dev ) {
|
void JoyPad::resetToDev(int dev ) {
|
||||||
//remember the device file descriptor
|
//remember the device file descriptor
|
||||||
joydev = dev;
|
joydev = dev;
|
||||||
|
|
||||||
//read in the number of axes / buttons
|
//read in the number of axes / buttons
|
||||||
axes = 0;
|
axes = 0;
|
||||||
ioctl (joydev, JSIOCGAXES, &axes);
|
ioctl (joydev, JSIOCGAXES, &axes);
|
||||||
buttons = 0;
|
buttons = 0;
|
||||||
ioctl (joydev, JSIOCGBUTTONS, &buttons);
|
ioctl (joydev, JSIOCGBUTTONS, &buttons);
|
||||||
|
|
||||||
//make sure that we have the axes we need.
|
//make sure that we have the axes we need.
|
||||||
//if one that we need doesn't yet exist, add it in.
|
//if one that we need doesn't yet exist, add it in.
|
||||||
//Note: if the current layout has a key assigned to an axis that did not
|
//Note: if the current layout has a key assigned to an axis that did not
|
||||||
//have a real joystick axis mapped to it, and this function suddenly brings
|
//have a real joystick axis mapped to it, and this function suddenly brings
|
||||||
//that axis into use, the key assignment will not be lost because the axis
|
//that axis into use, the key assignment will not be lost because the axis
|
||||||
//will already exist and no new axis will be created.
|
//will already exist and no new axis will be created.
|
||||||
for (int i = 0; i < axes; i++) {
|
for (int i = 0; i < axes; i++) {
|
||||||
if (Axes[i] == 0) Axes.insert(i, new Axis( i ));
|
if (Axes[i] == 0) Axes.insert(i, new Axis( i ));
|
||||||
}
|
}
|
||||||
for (int i = 0; i < buttons; i++) {
|
for (int i = 0; i < buttons; i++) {
|
||||||
if (Buttons[i] == 0) Buttons.insert(i, new Button( i ));
|
if (Buttons[i] == 0) Buttons.insert(i, new Button( i ));
|
||||||
}
|
}
|
||||||
struct pollfd read_struct;
|
|
||||||
read_struct.fd = joydev;
|
|
||||||
read_struct.events = POLLIN;
|
|
||||||
char buf[10];
|
|
||||||
while(poll(&read_struct, 1, 2)!=0) {
|
|
||||||
printf("reading junk data\n");
|
|
||||||
read(joydev, buf, 10);
|
|
||||||
}
|
|
||||||
setupJoyDeviceListener(dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JoyPad::setupJoyDeviceListener(int dev) {
|
|
||||||
if(joydevFileHandle != NULL) {
|
|
||||||
delete joydevFileHandle;
|
|
||||||
}
|
|
||||||
joydevFileHandle = new QSocketNotifier(dev, QSocketNotifier::Read, this);
|
|
||||||
connect(joydevFileHandle, SIGNAL(activated(int)), this, SLOT(handleJoyEvents(int)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoyPad::toDefault() {
|
void JoyPad::toDefault() {
|
||||||
//to reset the whole, reset all the parts.
|
//to reset the whole, reset all the parts.
|
||||||
do
|
for ( QIntDictIterator<Axis> it( Axes ); it.current(); ++it )
|
||||||
{
|
it.current()->toDefault();
|
||||||
QHashIterator<int, Axis*> it( Axes );
|
for ( QIntDictIterator<Button> it( Buttons ); it.current(); ++it )
|
||||||
while (it.hasNext())
|
it.current()->toDefault();
|
||||||
{
|
|
||||||
it.next();
|
|
||||||
it.value()->toDefault();
|
|
||||||
}
|
|
||||||
} while (0);
|
|
||||||
do
|
|
||||||
{
|
|
||||||
QHashIterator<int, Button*> it( Buttons );
|
|
||||||
while (it.hasNext())
|
|
||||||
{
|
|
||||||
it.next();
|
|
||||||
it.value()->toDefault();
|
|
||||||
}
|
|
||||||
} while (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JoyPad::isDefault() {
|
bool JoyPad::isDefault() {
|
||||||
//if any of the parts are not at default, then the whole isn't either.
|
//if any of the parts are not at default, then the whole isn't either.
|
||||||
do {
|
for ( QIntDictIterator<Axis> it( Axes ); it.current(); ++it )
|
||||||
QHashIterator<int, Axis*> it( Axes );
|
if (!it.current()->isDefault()) return false;
|
||||||
while (it.hasNext())
|
for ( QIntDictIterator<Button> it( Buttons ); it.current(); ++it )
|
||||||
{
|
if (!it.current()->isDefault()) return false;
|
||||||
it.next();
|
return true;
|
||||||
if (!it.value()->isDefault()) return false;
|
|
||||||
}
|
|
||||||
} while (0);
|
|
||||||
do {
|
|
||||||
QHashIterator<int, Button*> it( Buttons );
|
|
||||||
while (it.hasNext())
|
|
||||||
{
|
|
||||||
it.next();
|
|
||||||
if (!it.value()->isDefault()) return false;
|
|
||||||
}
|
|
||||||
} while (0);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JoyPad::readConfig( QTextStream* stream ) {
|
bool JoyPad::read( QTextStream* stream ) {
|
||||||
toDefault();
|
toDefault();
|
||||||
|
|
||||||
QString word;
|
QString word;
|
||||||
QChar dump;
|
QChar dump;
|
||||||
int num;
|
int num;
|
||||||
|
|
||||||
*stream >> word;
|
*stream >> word;
|
||||||
while (word != NULL && word != "}") {
|
while (word != NULL && word != "}") {
|
||||||
word = word.toLower();
|
word = word.lower();
|
||||||
if (word == "button") {
|
if (word == "button") {
|
||||||
*stream >> num;
|
*stream >> num;
|
||||||
if (num > 0) {
|
if (num > 0) {
|
||||||
*stream >> dump;
|
*stream >> dump;
|
||||||
if (dump != ':') {
|
if (dump != ':') {
|
||||||
error("Layout file error", "Expected ':', found '" + QString(dump) + "'.");
|
error("Layout file error", "Expected ':', found '" + QString(dump) + "'.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (Buttons[num-1] == 0) {
|
if (Buttons[num-1] == 0) {
|
||||||
Buttons.insert(num-1,new Button(num-1));
|
Buttons.insert(num-1,new Button(num-1));
|
||||||
}
|
}
|
||||||
if (!Buttons[num-1]->read( stream )) {
|
if (!Buttons[num-1]->read( stream )) {
|
||||||
error("Layout file error", "Error reading Button " + QString::number(num));
|
error("Layout file error", "Error reading Button " + QString::number(num));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
stream->readLine();
|
stream->readLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (word == "axis") {
|
else if (word == "axis") {
|
||||||
*stream >> num;
|
*stream >> num;
|
||||||
if (num > 0) {
|
if (num > 0) {
|
||||||
*stream >> dump;
|
*stream >> dump;
|
||||||
if (dump != ':') {
|
if (dump != ':') {
|
||||||
error("Layout file error", "Expected ':', found '" + QString(dump) + "'.");
|
error("Layout file error", "Expected ':', found '" + QString(dump) + "'.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (Axes[num-1] == 0) {
|
if (Axes[num-1] == 0) {
|
||||||
Axes.insert(num-1,new Axis(num-1));
|
Axes.insert(num-1,new Axis(num-1));
|
||||||
}
|
}
|
||||||
if (!Axes[num-1]->read(stream)) {
|
if (!Axes[num-1]->read(stream)) {
|
||||||
error("Layout file error", "Error reading Axis " + QString::number(num));
|
error("Layout file error", "Error reading Axis " + QString::number(num));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
error( "Layout file error", "Error while reading layout. Unrecognized word: " + word );
|
error( "Layout file error", "Error while reading layout. Unrecognized word: " + word );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
*stream >> word;
|
*stream >> word;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//only actually writes something if this JoyPad is NON DEFAULT.
|
//only actually writes something if this JoyPad is NON DEFAULT.
|
||||||
void JoyPad::write( QTextStream* stream ) {
|
void JoyPad::write( QTextStream* stream ) {
|
||||||
int i = 0; //use to test if this is default or not.
|
int i = 0; //use to test if this is default or not.
|
||||||
QString result;
|
QString result;
|
||||||
QTextStream* s = new QTextStream(&result, QIODevice::WriteOnly);
|
QTextStream* s = new QTextStream(&result, IO_WriteOnly);
|
||||||
*s << getName() << " {\n";
|
*s << getName() << " {\n";
|
||||||
do {
|
for ( QIntDictIterator<Axis> it( Axes ); it.current(); ++it ) {
|
||||||
QHashIterator<int, Axis*> it( Axes );
|
//only write an axis if it is not at the default settings :)
|
||||||
while (it.hasNext()) {
|
if (!it.current()->isDefault()) {
|
||||||
it.next();
|
it.current()->write( s );
|
||||||
if (!it.value()->isDefault()) {
|
++i;
|
||||||
it.value()->write( s );
|
}
|
||||||
++i;
|
}
|
||||||
}
|
for ( QIntDictIterator<Button> it( Buttons ); it.current(); ++it ) {
|
||||||
}
|
if (!it.current()->isDefault()) {
|
||||||
} while (0);
|
it.current()->write( s );
|
||||||
QHashIterator<int, Button*> it( Buttons );
|
++i;
|
||||||
while (it.hasNext()) {
|
}
|
||||||
it.next();
|
}
|
||||||
if (!it.value()->isDefault()) {
|
|
||||||
it.value()->write( s );
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
*stream << result << "}\n\n";
|
*stream << result << "}\n\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoyPad::release() {
|
void JoyPad::release() {
|
||||||
do {
|
for ( QIntDictIterator<Axis> it( Axes ); it.current(); ++it ) {
|
||||||
QHashIterator<int, Axis*> it( Axes );
|
it.current()->release();
|
||||||
while (it.hasNext()) {
|
}
|
||||||
it.next();
|
for ( QIntDictIterator<Button> it( Buttons ); it.current(); ++it ) {
|
||||||
it.value()->release();
|
it.current()->release();
|
||||||
}
|
}
|
||||||
} while (0);
|
|
||||||
do {
|
|
||||||
QHashIterator<int, Button*> it( Buttons );
|
|
||||||
while (it.hasNext()) {
|
|
||||||
it.next();
|
|
||||||
it.value()->release();
|
|
||||||
}
|
|
||||||
} while (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoyPad::jsevent( js_event msg ) {
|
void JoyPad::jsevent( js_event msg ) {
|
||||||
//if there is a JoyPadWidget around, ie, if the joypad is being edited
|
//if there is a JoyPadWidget around, ie, if the joypad is being edited
|
||||||
if (jpw != NULL) {
|
if (jpw != NULL) {
|
||||||
//tell the dialog there was an event. It will use this to flash
|
//tell the dialog there was an event. It will use this to flash
|
||||||
//the appropriate button, if necesary.
|
//the appropriate button, if necesary.
|
||||||
jpw->jsevent(msg);
|
jpw->jsevent(msg);
|
||||||
return;
|
}
|
||||||
}
|
//if the dialog is open, stop here. We don't want to signal ourselves with
|
||||||
//if the dialog is open, stop here. We don't want to signal ourselves with
|
//the input we generate.
|
||||||
//the input we generate.
|
if (qApp->activeWindow() != 0 && qApp->activeModalWidget() != 0) return;
|
||||||
if (qApp->activeWindow() != 0 && qApp->activeModalWidget() != 0) return;
|
|
||||||
|
|
||||||
//otherwise, lets create us a fake event! Pass on the event to whichever
|
//otherwise, lets create us a fake event! Pass on the event to whichever
|
||||||
//Button or Axis was pressed and let them decide what to do with it.
|
//Button or Axis was pressed and let them decide what to do with it.
|
||||||
if (msg.type & JS_EVENT_AXIS) {
|
if (msg.type & JS_EVENT_AXIS) {
|
||||||
printf("passing on an axis event\n");
|
Axes[msg.number]->jsevent(msg.value);
|
||||||
printf("DEBUG: %d %d\n", msg.number, msg.value);
|
}
|
||||||
Axes[msg.number]->jsevent(msg.value);
|
else {
|
||||||
}
|
Buttons[msg.number]->jsevent(msg.value);
|
||||||
else {
|
}
|
||||||
printf("passing on a button event\n");
|
|
||||||
printf("DEBUG: %d %d\n", msg.number, msg.value);
|
|
||||||
Buttons[msg.number]->jsevent(msg.value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JoyPadWidget* JoyPad::widget( QWidget* parent, int i) {
|
JoyPadWidget* JoyPad::widget( QWidget* parent, int i) {
|
||||||
//create the widget and remember it.
|
//create the widget and remember it.
|
||||||
jpw = new JoyPadWidget(this, i, parent);
|
jpw = new JoyPadWidget(this, i, parent);
|
||||||
return jpw;
|
return jpw;
|
||||||
}
|
|
||||||
|
|
||||||
void JoyPad::handleJoyEvents(int fd) {
|
|
||||||
js_event msg;
|
|
||||||
int len;
|
|
||||||
|
|
||||||
len = read( joydev, &msg, sizeof(js_event));
|
|
||||||
//if there was a real event waiting,
|
|
||||||
if (len == (int) sizeof(js_event)) {
|
|
||||||
//pass that event on to the joypad!
|
|
||||||
jsevent(msg);
|
|
||||||
} else {
|
|
||||||
printf("NOOOOOOO\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
//sleep for a moment. This is just to keep us from throwing all the
|
|
||||||
//available processer power into madly checking for new events.
|
|
||||||
//usleep(10000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoyPad::releaseWidget() {
|
void JoyPad::releaseWidget() {
|
||||||
//this is how we know that there is no longer a JoyPadWidget around.
|
//this is how we know that there is no longer a JoyPadWidget around.
|
||||||
jpw = NULL;
|
jpw = NULL;
|
||||||
}
|
|
||||||
|
|
||||||
void JoyPad::unsetDev() {
|
|
||||||
close(joydev);
|
|
||||||
joydev = -1;
|
|
||||||
if(joydevFileHandle != NULL) {
|
|
||||||
delete joydevFileHandle;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
41
src/joypad.h
41
src/joypad.h
@ -1,6 +1,19 @@
|
|||||||
#ifndef JOYPAD_H
|
#ifndef JOYPAD_H
|
||||||
#define JOYPAD_H
|
#define JOYPAD_H
|
||||||
|
|
||||||
|
//to have dictionaries of buttons and axes
|
||||||
|
#include <qintdict.h>
|
||||||
|
//the parent of JoyPadWidget
|
||||||
|
#include <qobject.h>
|
||||||
|
|
||||||
|
//for access to qApp so I can check if the application has active windows :)
|
||||||
|
#include <qapplication.h>
|
||||||
|
|
||||||
|
//for actually interacting with the joystick devices
|
||||||
|
#include <linux/joystick.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
//parts of the joypad
|
//parts of the joypad
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
#include "axis.h"
|
#include "axis.h"
|
||||||
@ -11,27 +24,16 @@
|
|||||||
//for raising errors
|
//for raising errors
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
|
||||||
//for actually interacting with the joystick devices
|
|
||||||
#include <linux/joystick.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <QTextStream>
|
|
||||||
#include <QHash>
|
|
||||||
#include <QSocketNotifier>
|
|
||||||
|
|
||||||
|
|
||||||
class JoyPadWidget;
|
class JoyPadWidget;
|
||||||
|
|
||||||
//represents an actual joystick device
|
//represents an actual joystick device
|
||||||
class JoyPad : public QObject{
|
class JoyPad : public QObject{
|
||||||
Q_OBJECT
|
friend class JoyPadWidget;
|
||||||
friend class JoyPadWidget;
|
|
||||||
friend class QuickSet;
|
friend class QuickSet;
|
||||||
public:
|
public:
|
||||||
void setupJoyDeviceListener(int dev);
|
JoyPad( int i, int dev );
|
||||||
JoyPad( int i, int dev );
|
//read from a stream
|
||||||
//read from a stream
|
bool read( QTextStream* stream );
|
||||||
bool readConfig( QTextStream* stream );
|
|
||||||
//write to a stream
|
//write to a stream
|
||||||
void write( QTextStream* stream );
|
void write( QTextStream* stream );
|
||||||
//release any pushed buttons and return to a neutral state
|
//release any pushed buttons and return to a neutral state
|
||||||
@ -43,7 +45,7 @@ class JoyPad : public QObject{
|
|||||||
//true iff this is currently at default settings
|
//true iff this is currently at default settings
|
||||||
bool isDefault();
|
bool isDefault();
|
||||||
//release the connection to the real joystick
|
//release the connection to the real joystick
|
||||||
void unsetDev();
|
void unsetDev() {close(joydev); joydev = -1;};
|
||||||
//read the dimensions on the real joystick and use them
|
//read the dimensions on the real joystick and use them
|
||||||
void resetToDev( int dev );
|
void resetToDev( int dev );
|
||||||
//generates a name ("Joystick 1")
|
//generates a name ("Joystick 1")
|
||||||
@ -64,17 +66,14 @@ class JoyPad : public QObject{
|
|||||||
//layouts with different numbers of axes/buttons than the current
|
//layouts with different numbers of axes/buttons than the current
|
||||||
//devices. Note that with the current layout settings, the defined
|
//devices. Note that with the current layout settings, the defined
|
||||||
//buttons that don't actually exist on the device may not be contiguous.
|
//buttons that don't actually exist on the device may not be contiguous.
|
||||||
QHash<int, Axis*> Axes;
|
QIntDict<Axis> Axes;
|
||||||
QHash<int, Button*> Buttons;
|
QIntDict<Button> Buttons;
|
||||||
//the index of this device (devicenum)
|
//the index of this device (devicenum)
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
//the widget that edits this. Mainly I keep track of this to know if
|
//the widget that edits this. Mainly I keep track of this to know if
|
||||||
//the joypad is currently being edited.
|
//the joypad is currently being edited.
|
||||||
JoyPadWidget* jpw;
|
JoyPadWidget* jpw;
|
||||||
QSocketNotifier *joydevFileHandle;
|
|
||||||
public slots:
|
|
||||||
void handleJoyEvents(int fd);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
139
src/joypadw.cpp
139
src/joypadw.cpp
@ -1,102 +1,93 @@
|
|||||||
#include "joypadw.h"
|
#include "joypadw.h"
|
||||||
//Added by qt3to4:
|
|
||||||
|
|
||||||
JoyPadWidget::JoyPadWidget( JoyPad* jp, int i, QWidget* parent )
|
JoyPadWidget::JoyPadWidget( JoyPad* jp, int i, QWidget* parent )
|
||||||
: QWidget(parent) {
|
: QWidget(parent) {
|
||||||
//initialize things, build the dialog
|
//initialize things, build the dialog
|
||||||
joypad = jp;
|
joypad = jp;
|
||||||
index = i;
|
index = i;
|
||||||
/* This was in below, no idea what it does :( ...
|
LMain = new QGridLayout(this, (joypad->axes+1)/2 +(joypad->buttons+1)/2 + 2, 2, 5, 5);
|
||||||
* (joypad->axes+1)/2 +(joypad->buttons+1)/2 + 2
|
LMain->setAutoAdd( true );
|
||||||
*/
|
flashcount = 0;
|
||||||
LMain = new QGridLayout(this);
|
quickset = NULL;
|
||||||
LMain->setSpacing(5);
|
|
||||||
LMain->setMargin(5);
|
|
||||||
flashcount = 0;
|
|
||||||
int insertCounter = 0;
|
|
||||||
quickset = NULL;
|
|
||||||
|
|
||||||
Axes = new AxisWidget*[joypad->axes];
|
Axes = new AxisWidget*[joypad->axes];
|
||||||
for (int i = 0; i < joypad->axes; i++) {
|
for (int i = 0; i < joypad->axes; i++) {
|
||||||
Axes[i] = new AxisWidget(joypad->Axes[i],this);
|
Axes[i] = new AxisWidget(joypad->Axes[i],this);
|
||||||
connect( Axes[i], SIGNAL( flashed( bool ) ), this, SLOT( flash( bool )));
|
connect( Axes[i], SIGNAL( flashed( bool ) ), this, SLOT( flash( bool )));
|
||||||
LMain->addWidget(Axes[i], insertCounter / 2, insertCounter %2);
|
}
|
||||||
insertCounter++;
|
if (joypad->axes % 2 == 1) {
|
||||||
}
|
new QWidget(this);
|
||||||
|
}
|
||||||
|
|
||||||
Buttons = new ButtonWidget*[joypad->buttons];
|
Buttons = new ButtonWidget*[joypad->buttons];
|
||||||
for (int i = 0; i < joypad->buttons; i++) {
|
for (int i = 0; i < joypad->buttons; i++) {
|
||||||
Buttons[i] = new ButtonWidget(joypad->Buttons[i],this);
|
Buttons[i] = new ButtonWidget(joypad->Buttons[i],this);
|
||||||
connect( Buttons[i], SIGNAL( flashed( bool ) ), this, SLOT( flash( bool )));
|
connect( Buttons[i], SIGNAL( flashed( bool ) ), this, SLOT( flash( bool )));
|
||||||
LMain->addWidget(Buttons[i], insertCounter/2, insertCounter%2);
|
}
|
||||||
insertCounter++;
|
if (joypad->buttons % 2 == 1) {
|
||||||
}
|
new QWidget(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
new QWidget(this);
|
||||||
|
new QWidget(this);
|
||||||
|
|
||||||
if(insertCounter % 2 == 1) {
|
BClear = new QPushButton("Clear", this);
|
||||||
insertCounter++;
|
connect(BClear, SIGNAL(clicked()), this, SLOT(clear()));
|
||||||
}
|
BAll = new QPushButton("Quick Set", this);
|
||||||
insertCounter+=2;
|
connect(BAll, SIGNAL(clicked()), this, SLOT(setAll()));
|
||||||
BClear = new QPushButton("Clear", this);
|
|
||||||
connect(BClear, SIGNAL(clicked()), this, SLOT(clear()));
|
|
||||||
LMain->addWidget(BClear, insertCounter / 2, insertCounter %2);
|
|
||||||
insertCounter++;
|
|
||||||
BAll = new QPushButton("Quick Set", this);
|
|
||||||
LMain->addWidget(BAll, insertCounter /2, insertCounter%2);
|
|
||||||
connect(BAll, SIGNAL(clicked()), this, SLOT(setAll()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JoyPadWidget::~JoyPadWidget() {
|
JoyPadWidget::~JoyPadWidget() {
|
||||||
//so the joypad knows that we're done.
|
//so the joypad knows that we're done.
|
||||||
joypad->releaseWidget();
|
joypad->releaseWidget();
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoyPadWidget::flash( bool on ) {
|
void JoyPadWidget::flash( bool on ) {
|
||||||
//true iff this entire widget was considered "flashed" before
|
//true iff this entire widget was considered "flashed" before
|
||||||
bool wasOn = (flashcount != 0);
|
bool wasOn = (flashcount != 0);
|
||||||
|
|
||||||
//adjust the count based on this new flash
|
//adjust the count based on this new flash
|
||||||
flashcount += (on?1:-1);
|
flashcount += (on?1:-1);
|
||||||
|
|
||||||
//if we were on and should now be off, or visa versa, flash the whole widget
|
//if we were on and should now be off, or visa versa, flash the whole widget
|
||||||
if (wasOn != (flashcount != 0))
|
if (wasOn != (flashcount != 0))
|
||||||
emit flashed(index);
|
emit flashed(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoyPadWidget::update() {
|
void JoyPadWidget::update() {
|
||||||
for (int i = 0; i < joypad->axes; i++) {
|
for (int i = 0; i < joypad->axes; i++) {
|
||||||
Axes[i]->update();
|
Axes[i]->update();
|
||||||
}
|
}
|
||||||
for (int i = 0; i < joypad->buttons; i++) {
|
for (int i = 0; i < joypad->buttons; i++) {
|
||||||
Buttons[i]->update();
|
Buttons[i]->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoyPadWidget::clear() {
|
void JoyPadWidget::clear() {
|
||||||
joypad->toDefault();
|
joypad->toDefault();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoyPadWidget::setAll() {
|
void JoyPadWidget::setAll() {
|
||||||
//quickset is NULL if there is no quickset dialog, and a pointer to the
|
//quickset is NULL if there is no quickset dialog, and a pointer to the
|
||||||
//dialog otherwise. This is so we can forward jsevents properly.
|
//dialog otherwise. This is so we can forward jsevents properly.
|
||||||
quickset = new QuickSet(joypad);
|
quickset = new QuickSet(joypad);
|
||||||
quickset->exec();
|
quickset->exec();
|
||||||
update();
|
update();
|
||||||
delete quickset;
|
delete quickset;
|
||||||
quickset = NULL;
|
quickset = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoyPadWidget::jsevent( js_event msg ) {
|
void JoyPadWidget::jsevent( js_event msg ) {
|
||||||
//notify the component this event applies to. this cannot generate anything
|
//notify the component this event applies to. this cannot generate anything
|
||||||
//other than a flash :)
|
//other than a flash :)
|
||||||
if (msg.type == JS_EVENT_AXIS) {
|
if (msg.type == JS_EVENT_AXIS) {
|
||||||
Axes[msg.number]->jsevent(msg.value);
|
Axes[msg.number]->jsevent(msg.value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Buttons[msg.number]->jsevent(msg.value);
|
Buttons[msg.number]->jsevent(msg.value);
|
||||||
}
|
}
|
||||||
//if we're doing quickset, it needs to know when we do something.
|
//if we're doing quickset, it needs to know when we do something.
|
||||||
if (quickset != NULL)
|
if (quickset != NULL)
|
||||||
quickset->jsevent(msg);
|
quickset->jsevent(msg);
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
#define JOYPAD_WIDGET_H
|
#define JOYPAD_WIDGET_H
|
||||||
|
|
||||||
//parts for the widget
|
//parts for the widget
|
||||||
//Added by qt3to4:
|
#include <qpushbutton.h>
|
||||||
|
#include <qlayout.h>
|
||||||
|
|
||||||
#include <linux/joystick.h>
|
|
||||||
#include "axisw.h"
|
|
||||||
//this all relates to a JoyPad
|
//this all relates to a JoyPad
|
||||||
#include "joypad.h"
|
#include "joypad.h"
|
||||||
//and a JoyPadWidget is composed of AxisWidgets and ButtonWidgets
|
//and a JoyPadWidget is composed of AxisWidgets and ButtonWidgets
|
||||||
|
#include "axisw.h"
|
||||||
#include "buttonw.h"
|
#include "buttonw.h"
|
||||||
//JoyPadWidget also is what initiates the whole QuickSet procedure :)
|
//JoyPadWidget also is what initiates the whole QuickSet procedure :)
|
||||||
#include "quickset.h"
|
#include "quickset.h"
|
||||||
|
@ -1,239 +1,238 @@
|
|||||||
#include "joyslider.h"
|
#include "joyslider.h"
|
||||||
//Added by qt3to4:
|
|
||||||
|
|
||||||
JoySlider::JoySlider( int dz, int xz, int val, QWidget* parent )
|
JoySlider::JoySlider( int dz, int xz, int val, QWidget* parent )
|
||||||
:QWidget( parent )
|
:QWidget( parent )
|
||||||
{
|
{
|
||||||
//initialize :)
|
//initialize :)
|
||||||
JoyVal = val;
|
JoyVal = val;
|
||||||
DeadZone = dz;
|
DeadZone = dz;
|
||||||
XZone = xz;
|
XZone = xz;
|
||||||
setMinimumHeight(20);
|
setMinimumHeight(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoySlider::setValue( int newval )
|
void JoySlider::setValue( int newval )
|
||||||
{
|
{
|
||||||
//adjust the new position based on the throttle settings
|
//adjust the new position based on the throttle settings
|
||||||
if (throttle == 0) JoyVal = newval;
|
if (throttle == 0) JoyVal = newval;
|
||||||
else if (throttle < 0) JoyVal = (newval + JOYMIN) / 2;
|
else if (throttle < 0) JoyVal = (newval + JOYMIN) / 2;
|
||||||
else JoyVal = (newval + JOYMAX) / 2;
|
else JoyVal = (newval + JOYMAX) / 2;
|
||||||
//then redraw!
|
//then redraw!
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoySlider::setThrottle( int newval )
|
void JoySlider::setThrottle( int newval )
|
||||||
{
|
{
|
||||||
//change throttle settings. This WILL quite likely cause minor issues with
|
//change throttle settings. This WILL quite likely cause minor issues with
|
||||||
//status if the axis is not currently at zero, but these will be corrected
|
//status if the axis is not currently at zero, but these will be corrected
|
||||||
//as soon as the axis moves again.
|
//as soon as the axis moves again.
|
||||||
throttle = newval;
|
throttle = newval;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
int JoySlider::pointFor( int value, bool negative )
|
int JoySlider::pointFor( int value, bool negative )
|
||||||
{
|
{
|
||||||
//complicated... this just finds the pixel the given value should be.
|
//complicated... this just finds the pixel the given value should be.
|
||||||
if (throttle == 0) {
|
if (throttle == 0) {
|
||||||
int result = ((boxwidth - 4) * value) / JOYMAX;
|
int result = ((boxwidth - 4) * value) / JOYMAX;
|
||||||
if (negative) result = lboxstart + boxwidth - 2 - result;
|
if (negative) result = lboxstart + boxwidth - 2 - result;
|
||||||
else result += rboxstart + 2;
|
else result += rboxstart + 2;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int result = ((twidth - 4) * value) / JOYMAX;
|
int result = ((twidth - 4) * value) / JOYMAX;
|
||||||
if (negative) result = lboxstart + twidth - 2 - result;
|
if (negative) result = lboxstart + twidth - 2 - result;
|
||||||
else result += lboxstart + 2;
|
else result += lboxstart + 2;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int JoySlider::valueFrom( int point )
|
int JoySlider::valueFrom( int point )
|
||||||
{
|
{
|
||||||
//the inverse of above :)
|
//the inverse of above :)
|
||||||
if (throttle == 0) {
|
if (throttle == 0) {
|
||||||
if (point <= lboxstart) return JOYMAX;
|
if (point <= lboxstart) return JOYMAX;
|
||||||
if (point >= lboxend - 2 && point <= rboxstart + 2) return 0;
|
if (point >= lboxend - 2 && point <= rboxstart + 2) return 0;
|
||||||
if (point >= rboxend - 2) return JOYMAX;
|
if (point >= rboxend - 2) return JOYMAX;
|
||||||
if (point < lboxend - 2) return ((lboxend - point) * JOYMAX) / boxwidth;
|
if (point < lboxend - 2) return ((lboxend - point) * JOYMAX) / boxwidth;
|
||||||
if (point > rboxstart) return ((point - rboxstart) * JOYMAX) / boxwidth;
|
if (point > rboxstart) return ((point - rboxstart) * JOYMAX) / boxwidth;
|
||||||
else return 0;
|
else return 0;
|
||||||
}
|
}
|
||||||
else if (throttle > 0) {
|
else if (throttle > 0) {
|
||||||
if (point <= lboxstart) return 0;
|
if (point <= lboxstart) return 0;
|
||||||
else if (point >= tend) return JOYMAX;
|
else if (point >= tend) return JOYMAX;
|
||||||
else return ((point - lboxstart) * JOYMAX) / twidth;
|
else return ((point - lboxstart) * JOYMAX) / twidth;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (point <= lboxstart - 2) return JOYMAX;
|
if (point <= lboxstart - 2) return JOYMAX;
|
||||||
else if (point >= tend) return 0;
|
else if (point >= tend) return 0;
|
||||||
else return ((tend - point) * JOYMAX) / twidth;
|
else return ((tend - point) * JOYMAX) / twidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoySlider::resizeEvent( QResizeEvent* )
|
void JoySlider::resizeEvent( QResizeEvent* )
|
||||||
{
|
{
|
||||||
//when we resize, we need to recalculate a bunch of measurements.
|
//when we resize, we need to recalculate a bunch of measurements.
|
||||||
boxwidth = (this->width() - 6) / 2 - 1;
|
boxwidth = (this->width() - 6) / 2 - 1;
|
||||||
twidth = this->width() - 4;
|
twidth = this->width() - 4;
|
||||||
boxheight = this->height() - 4;
|
boxheight = this->height() - 4;
|
||||||
lboxstart = 1;
|
lboxstart = 1;
|
||||||
lboxend = lboxstart + boxwidth - 1;
|
lboxend = lboxstart + boxwidth - 1;
|
||||||
tend = lboxstart + twidth - 1;
|
tend = lboxstart + twidth - 1;
|
||||||
rboxstart = lboxend + 5;
|
rboxstart = lboxend + 5;
|
||||||
rboxend = rboxstart + boxwidth - 1;
|
rboxend = rboxstart + boxwidth - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoySlider::drawBox( int x, int width ) {
|
void JoySlider::drawBox( int x, int width ) {
|
||||||
//draws a nice, pretty, 3d-styled box. that takes up the full height of the
|
//draws a nice, pretty, 3d-styled box. that takes up the full height of the
|
||||||
//widget but is defined by x-coordinate and width
|
//widget but is defined by x-coordinate and width
|
||||||
QPainter paint( this );
|
QPainter paint( this );
|
||||||
|
|
||||||
paint.setPen( (isEnabled())?Qt::white:palette().background().color() );
|
paint.setPen( (isEnabled())?white:colorGroup().background() );
|
||||||
paint.setBrush( (isEnabled())?Qt::white:palette().background() );
|
paint.setBrush( (isEnabled())?white:colorGroup().background() );
|
||||||
paint.drawRect( x, 1, width, boxheight);
|
paint.drawRect( x, 1, width, boxheight);
|
||||||
|
|
||||||
paint.setPen( palette().dark().color() );
|
paint.setPen( colorGroup().dark() );
|
||||||
paint.drawLine( x, 1 + boxheight, x, 1 );
|
paint.drawLine( x, 1 + boxheight, x, 1 );
|
||||||
paint.drawLine( x, 1, x + width - 1, 1);
|
paint.drawLine( x, 1, x + width - 1, 1);
|
||||||
|
|
||||||
paint.setPen( palette().shadow().color() );
|
paint.setPen( colorGroup().shadow() );
|
||||||
paint.drawLine( x + 1, 1 + boxheight - 1, x + 1, 2);
|
paint.drawLine( x + 1, 1 + boxheight - 1, x + 1, 2);
|
||||||
paint.drawLine( x + 1, 2, x + width - 2, 2);
|
paint.drawLine( x + 1, 2, x + width - 2, 2);
|
||||||
|
|
||||||
paint.setPen( palette().light().color() );
|
paint.setPen( colorGroup().light() );
|
||||||
paint.drawLine( x + 2, 1 + boxheight - 1, x + width - 1, 1 + boxheight - 1);
|
paint.drawLine( x + 2, 1 + boxheight - 1, x + width - 1, 1 + boxheight - 1);
|
||||||
paint.drawLine( x + width - 1, 1 + boxheight - 1, x + width - 1, 2);
|
paint.drawLine( x + width - 1, 1 + boxheight - 1, x + width - 1, 2);
|
||||||
|
|
||||||
paint.setPen( palette().midlight().color() );
|
paint.setPen( colorGroup().midlight() );
|
||||||
paint.drawLine( x + 1, 1 + boxheight, x + width, 1 + boxheight );
|
paint.drawLine( x + 1, 1 + boxheight, x + width, 1 + boxheight );
|
||||||
paint.drawLine( x + width, 1 + boxheight, x + width, 1 );
|
paint.drawLine( x + width, 1 + boxheight, x + width, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoySlider::paintEvent( QPaintEvent* )
|
void JoySlider::paintEvent( QPaintEvent* )
|
||||||
{
|
{
|
||||||
//when we need to redraw,
|
//when we need to redraw,
|
||||||
//start by making our boxes
|
//start by making our boxes
|
||||||
if (throttle == 0) {
|
if (throttle == 0) {
|
||||||
drawBox( lboxstart, boxwidth );
|
drawBox( lboxstart, boxwidth );
|
||||||
drawBox( rboxstart, boxwidth );
|
drawBox( rboxstart, boxwidth );
|
||||||
}
|
}
|
||||||
//or box, if we are in throttle mode.
|
//or box, if we are in throttle mode.
|
||||||
else {
|
else {
|
||||||
drawBox( lboxstart, twidth );
|
drawBox( lboxstart, twidth );
|
||||||
}
|
}
|
||||||
|
|
||||||
//if this is disabled, that's enough of that.
|
//if this is disabled, that's enough of that.
|
||||||
if (!isEnabled()) return;
|
if (!isEnabled()) return;
|
||||||
|
|
||||||
//now we need to draw.
|
//now we need to draw.
|
||||||
QPainter paint( this );
|
QPainter paint( this );
|
||||||
|
|
||||||
//prepare to draw a bar of the appropriate color
|
//prepare to draw a bar of the appropriate color
|
||||||
QColor bar;
|
QColor bar;
|
||||||
if (abs(JoyVal) < DeadZone) bar = Qt::gray;
|
if (abs(JoyVal) < DeadZone) bar = gray;
|
||||||
else if (abs(JoyVal) < XZone) bar = Qt::blue;
|
else if (abs(JoyVal) < XZone) bar = blue;
|
||||||
else bar = Qt::red;
|
else bar = red;
|
||||||
paint.setPen( bar );
|
paint.setPen( bar );
|
||||||
paint.setBrush( bar );
|
paint.setBrush( bar );
|
||||||
|
|
||||||
//find out the dimensions of the bar, then draw it
|
//find out the dimensions of the bar, then draw it
|
||||||
int width = (throttle == 0)?boxwidth:twidth;
|
int width = (throttle == 0)?boxwidth:twidth;
|
||||||
int barlen = abs(((width - 4) * JoyVal) / JOYMAX);
|
int barlen = abs(((width - 4) * JoyVal) / JOYMAX);
|
||||||
if (JoyVal > 0)
|
if (JoyVal > 0)
|
||||||
paint.drawRect( ((throttle == 0)?rboxstart:lboxstart) + 2, 3, barlen, boxheight - 3 );
|
paint.drawRect( ((throttle == 0)?rboxstart:lboxstart) + 2, 3, barlen, boxheight - 3 );
|
||||||
else if (JoyVal < 0)
|
else if (JoyVal < 0)
|
||||||
paint.drawRect( lboxstart + width - 2 - barlen, 3, barlen, boxheight - 3 );
|
paint.drawRect( lboxstart + width - 2 - barlen, 3, barlen, boxheight - 3 );
|
||||||
|
|
||||||
|
|
||||||
//and now draw the tabs! We only need one set if we're doing a throttle mode
|
//and now draw the tabs! We only need one set if we're doing a throttle mode
|
||||||
//but we need two if we're not. However, it's important to draw the right
|
//but we need two if we're not. However, it's important to draw the right
|
||||||
//set of tabs depending on the mode! Negative throttle gets negative tabs.
|
//set of tabs depending on the mode! Negative throttle gets negative tabs.
|
||||||
int point;
|
int point;
|
||||||
QPolygon shape;
|
QPointArray shape;
|
||||||
|
|
||||||
paint.setPen( Qt::black );
|
paint.setPen( black );
|
||||||
paint.setBrush( Qt::blue );
|
paint.setBrush( blue );
|
||||||
if (throttle >= 0) {
|
if (throttle >= 0) {
|
||||||
point = pointFor(DeadZone, false);
|
point = pointFor(DeadZone, false);
|
||||||
shape.putPoints(0,5,
|
shape.putPoints(0,5,
|
||||||
point, boxheight - 4,
|
point, boxheight - 4,
|
||||||
point + 3, boxheight - 1,
|
point + 3, boxheight - 1,
|
||||||
point + 3, boxheight + 2,
|
point + 3, boxheight + 2,
|
||||||
point - 3, boxheight + 2,
|
point - 3, boxheight + 2,
|
||||||
point - 3, boxheight - 1);
|
point - 3, boxheight - 1);
|
||||||
paint.drawPolygon(shape);
|
paint.drawPolygon(shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (throttle <= 0) {
|
if (throttle <= 0) {
|
||||||
point = pointFor(DeadZone, true);
|
point = pointFor(DeadZone, true);
|
||||||
shape.putPoints(0,5,
|
shape.putPoints(0,5,
|
||||||
point, boxheight - 4,
|
point, boxheight - 4,
|
||||||
point + 3, boxheight - 1,
|
point + 3, boxheight - 1,
|
||||||
point + 3, boxheight + 2,
|
point + 3, boxheight + 2,
|
||||||
point - 3, boxheight + 2,
|
point - 3, boxheight + 2,
|
||||||
point - 3, boxheight - 1);
|
point - 3, boxheight - 1);
|
||||||
paint.drawPolygon(shape);
|
paint.drawPolygon(shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
paint.setBrush( Qt::red );
|
paint.setBrush( red );
|
||||||
if (throttle >= 0) {
|
if (throttle >= 0) {
|
||||||
point = pointFor(XZone, false);
|
point = pointFor(XZone, false);
|
||||||
shape.putPoints(0,5,
|
shape.putPoints(0,5,
|
||||||
point, boxheight - 4,
|
point, boxheight - 4,
|
||||||
point + 3, boxheight - 1,
|
point + 3, boxheight - 1,
|
||||||
point + 3, boxheight + 2,
|
point + 3, boxheight + 2,
|
||||||
point - 3, boxheight + 2,
|
point - 3, boxheight + 2,
|
||||||
point - 3, boxheight - 1);
|
point - 3, boxheight - 1);
|
||||||
paint.drawPolygon(shape);
|
paint.drawPolygon(shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (throttle <= 0) {
|
if (throttle <= 0) {
|
||||||
point = pointFor(XZone, true);
|
point = pointFor(XZone, true);
|
||||||
shape.putPoints(0,5,
|
shape.putPoints(0,5,
|
||||||
point, boxheight - 4,
|
point, boxheight - 4,
|
||||||
point + 3, boxheight - 1,
|
point + 3, boxheight - 1,
|
||||||
point + 3, boxheight + 2,
|
point + 3, boxheight + 2,
|
||||||
point - 3, boxheight + 2,
|
point - 3, boxheight + 2,
|
||||||
point - 3, boxheight - 1);
|
point - 3, boxheight - 1);
|
||||||
paint.drawPolygon(shape);
|
paint.drawPolygon(shape);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoySlider::mousePressEvent( QMouseEvent* e )
|
void JoySlider::mousePressEvent( QMouseEvent* e )
|
||||||
{
|
{
|
||||||
//store the x coordinate.
|
//store the x coordinate.
|
||||||
int xpt = e->x();
|
int xpt = e->x();
|
||||||
int result = 0;
|
int result = 0;
|
||||||
//see if this happened near one of the tabs. If so, start dragging that tab.
|
//see if this happened near one of the tabs. If so, start dragging that tab.
|
||||||
if (throttle <= 0 && abs( xpt - pointFor( XZone, true )) < 5) result = DRAG_XZ;
|
if (throttle <= 0 && abs( xpt - pointFor( XZone, true )) < 5) result = DRAG_XZ;
|
||||||
else if (throttle <= 0 && abs( xpt - pointFor( DeadZone, true )) < 5) result = DRAG_DZ;
|
else if (throttle <= 0 && abs( xpt - pointFor( DeadZone, true )) < 5) result = DRAG_DZ;
|
||||||
else if (throttle >= 0 && abs( xpt - pointFor( XZone, false )) < 5) result = DRAG_XZ;
|
else if (throttle >= 0 && abs( xpt - pointFor( XZone, false )) < 5) result = DRAG_XZ;
|
||||||
else if (throttle >= 0 && abs( xpt - pointFor( DeadZone, false )) < 5) result = DRAG_DZ;
|
else if (throttle >= 0 && abs( xpt - pointFor( DeadZone, false )) < 5) result = DRAG_DZ;
|
||||||
dragging = result;
|
dragging = result;
|
||||||
};
|
};
|
||||||
|
|
||||||
void JoySlider::mouseReleaseEvent( QMouseEvent* )
|
void JoySlider::mouseReleaseEvent( QMouseEvent* )
|
||||||
{
|
{
|
||||||
//when the mouse releases, all dragging stops.
|
//when the mouse releases, all dragging stops.
|
||||||
dragging = 0;
|
dragging = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoySlider::mouseMoveEvent( QMouseEvent* e )
|
void JoySlider::mouseMoveEvent( QMouseEvent* e )
|
||||||
{
|
{
|
||||||
//get the x coordinate
|
//get the x coordinate
|
||||||
int xpt = e->x();
|
int xpt = e->x();
|
||||||
//if we're dragging, move the appropriate tab!
|
//if we're dragging, move the appropriate tab!
|
||||||
if (dragging == DRAG_XZ)
|
if (dragging == DRAG_XZ)
|
||||||
{
|
{
|
||||||
XZone = valueFrom( xpt );
|
XZone = valueFrom( xpt );
|
||||||
}
|
}
|
||||||
else if (dragging == DRAG_DZ)
|
else if (dragging == DRAG_DZ)
|
||||||
{
|
{
|
||||||
DeadZone = valueFrom( xpt );
|
DeadZone = valueFrom( xpt );
|
||||||
}
|
}
|
||||||
else return;
|
else return;
|
||||||
//if we moved a tab, redraw!
|
//if we moved a tab, redraw!
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,12 @@
|
|||||||
#define Q_JOYSLIDER_H
|
#define Q_JOYSLIDER_H
|
||||||
|
|
||||||
//the parent of this
|
//the parent of this
|
||||||
|
#include <qwidget.h>
|
||||||
|
//for drawing the widget :)
|
||||||
|
#include <qpainter.h>
|
||||||
|
//for abs()
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <QResizeEvent>
|
|
||||||
#include <QPaintEvent>
|
|
||||||
#include <QMouseEvent>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QFrame>
|
|
||||||
#include <QHBoxLayout>
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
#include <QComboBox>
|
|
||||||
#include <QSpinBox>
|
|
||||||
#include "constant.h"
|
#include "constant.h"
|
||||||
|
|
||||||
//dragging constants.
|
//dragging constants.
|
||||||
|
213
src/keycode.cpp
213
src/keycode.cpp
@ -1,13 +1,13 @@
|
|||||||
#include "keycode.h"
|
#include "keycode.h"
|
||||||
#include "getkey.h"
|
|
||||||
|
|
||||||
const QString ktos( int keycode )
|
const QString ktos( int keycode )
|
||||||
{
|
{
|
||||||
if (keycode > MAXKEY || keycode < 0) keycode = 0;
|
if (keycode > MAXKEY || keycode < 0) keycode = 0;
|
||||||
|
|
||||||
if (keycode == 0) return "[NO KEY]";
|
if (keycode == 0) return "[NO KEY]";
|
||||||
|
|
||||||
QString xname = XKeysymToString(XKeycodeToKeysym(display, keycode,0));
|
QString xname = XKeysymToString(XKeycodeToKeysym(display, keycode,0));
|
||||||
|
|
||||||
//this section of code converts standard X11 keynames into much nicer names
|
//this section of code converts standard X11 keynames into much nicer names
|
||||||
//which are prettier, fit the dialogs better, and are more readily understandable.
|
//which are prettier, fit the dialogs better, and are more readily understandable.
|
||||||
@ -15,90 +15,155 @@ const QString ktos( int keycode )
|
|||||||
//is a config option to define PLAIN_KEYS and drop this whole section of code,
|
//is a config option to define PLAIN_KEYS and drop this whole section of code,
|
||||||
//instead using the default names for keys.
|
//instead using the default names for keys.
|
||||||
#ifndef PLAIN_KEYS
|
#ifndef PLAIN_KEYS
|
||||||
//the following code assumes xname is system independent and always
|
//the following code assumes xname is system independent and always
|
||||||
//in the same exact format.
|
//in the same exact format.
|
||||||
|
|
||||||
QRegExp rx;
|
QRegExp rx;
|
||||||
rx.setPattern("^\\w$");
|
rx.setPattern("^\\w$");
|
||||||
//"a-z" -> "A-Z"
|
//"a-z" -> "A-Z"
|
||||||
if (rx.exactMatch(xname)) return xname.toUpper();
|
if (rx.exactMatch(xname)) return xname.upper();
|
||||||
|
|
||||||
rx.setPattern("(.*)_(.*)");
|
rx.setPattern("(.*)_(.*)");
|
||||||
if (rx.exactMatch(xname)) {
|
if (rx.exactMatch(xname)) {
|
||||||
QString first = rx.cap(1);
|
QString first = rx.cap(1);
|
||||||
QString second = rx.cap(2);
|
QString second = rx.cap(2);
|
||||||
|
|
||||||
rx.setPattern("^[RL]$");
|
rx.setPattern("^[RL]$");
|
||||||
//"Control_R" -> "R Control"
|
//"Control_R" -> "R Control"
|
||||||
if (rx.exactMatch(second)) return second + " " + first;
|
if (rx.exactMatch(second)) return second + " " + first;
|
||||||
|
|
||||||
rx.setPattern("^(Lock|Enter)$");
|
rx.setPattern("^(Lock|Enter)$");
|
||||||
//"Caps_Lock" -> "Caps Lock"
|
//"Caps_Lock" -> "Caps Lock"
|
||||||
//"KP_Enter" -> "KP Enter"
|
//"KP_Enter" -> "KP Enter"
|
||||||
if (rx.exactMatch(second)) return first + " " + second;
|
if (rx.exactMatch(second)) return first + " " + second;
|
||||||
|
|
||||||
//the following assumes all number pads are laid out alike.
|
//the following assumes all number pads are laid out alike.
|
||||||
if (xname == "KP_Home") return "KP 7";
|
if (xname == "KP_Home") return "KP 7";
|
||||||
if (xname == "KP_Up") return "KP 8";
|
if (xname == "KP_Up") return "KP 8";
|
||||||
if (xname == "KP_Prior") return "KP 9";
|
if (xname == "KP_Prior") return "KP 9";
|
||||||
if (xname == "KP_Subtract") return "KP -";
|
if (xname == "KP_Subtract") return "KP -";
|
||||||
if (xname == "KP_Left") return "KP 4";
|
if (xname == "KP_Left") return "KP 4";
|
||||||
if (xname == "KP_Begin") return "KP 5";
|
if (xname == "KP_Begin") return "KP 5";
|
||||||
if (xname == "KP_Right") return "KP 6";
|
if (xname == "KP_Right") return "KP 6";
|
||||||
if (xname == "KP_Add") return "KP +";
|
if (xname == "KP_Add") return "KP +";
|
||||||
if (xname == "KP_End") return "KP 1";
|
if (xname == "KP_End") return "KP 1";
|
||||||
if (xname == "KP_Down") return "KP 2";
|
if (xname == "KP_Down") return "KP 2";
|
||||||
if (xname == "KP_Next") return "KP 3";
|
if (xname == "KP_Next") return "KP 3";
|
||||||
if (xname == "KP_Insert") return "KP 0";
|
if (xname == "KP_Insert") return "KP 0";
|
||||||
if (xname == "KP_Delete") return "KP .";
|
if (xname == "KP_Delete") return "KP .";
|
||||||
if (xname == "KP_Multiply") return "KP *";
|
if (xname == "KP_Multiply") return "KP *";
|
||||||
if (xname == "KP_Divide") return "KP /";
|
if (xname == "KP_Divide") return "KP /";
|
||||||
|
|
||||||
return xname;
|
return xname;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xname == "minus") return "-";
|
if (xname == "minus") return "-";
|
||||||
if (xname == "equal") return "=";
|
if (xname == "equal") return "=";
|
||||||
if (xname == "bracketleft") return "[";
|
if (xname == "bracketleft") return "[";
|
||||||
if (xname == "bracketright") return "]";
|
if (xname == "bracketright") return "]";
|
||||||
if (xname == "semicolon") return ";";
|
if (xname == "semicolon") return ";";
|
||||||
if (xname == "apostrophe") return "'";
|
if (xname == "apostrophe") return "'";
|
||||||
if (xname == "grave") return "`";
|
if (xname == "grave") return "`";
|
||||||
if (xname == "backslash") return "\\";
|
if (xname == "backslash") return "\\";
|
||||||
if (xname == "comma") return ",";
|
if (xname == "comma") return ",";
|
||||||
if (xname == "period") return ".";
|
if (xname == "period") return ".";
|
||||||
if (xname == "slash") return "/";
|
if (xname == "slash") return "/";
|
||||||
if (xname == "space") return "Space";
|
if (xname == "space") return "Space";
|
||||||
if (xname == "Prior") return "PageUp";
|
if (xname == "Prior") return "PageUp";
|
||||||
if (xname == "Next") return "PageDown";
|
if (xname == "Next") return "PageDown";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//if none of that succeeded,
|
//if none of that succeeded,
|
||||||
return xname;
|
return xname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
GetKey::GetKey( QString button, bool m )
|
||||||
|
:QDialog( )
|
||||||
|
{
|
||||||
|
//prepare the dialog
|
||||||
|
mouse = m;
|
||||||
|
setCaption( "Choose a key" );
|
||||||
|
setIcon(QPixmap(ICON24));
|
||||||
|
|
||||||
|
//I'd use a QLabel, but that steals x11Events!
|
||||||
|
//So, I'll draw the text directly. That means
|
||||||
|
//I need to resolve the size of the dialog by hand:
|
||||||
|
Text = "Choose a new key ";
|
||||||
|
if (mouse) Text += "or mouse button ";
|
||||||
|
Text += "for " + button;
|
||||||
|
QRect rect = fontMetrics().boundingRect( Text );
|
||||||
|
//I calculate the size based on the first line of text, which is longer.
|
||||||
|
//The fontMetrics function is dumb and would treat the string with a
|
||||||
|
//newline in it as a continues flow of characters if I did the whole string
|
||||||
|
//at once.
|
||||||
|
Text += "\n(Ctrl-X for no key)";
|
||||||
|
//now I add 20 pixels of padding and double the height to make room for
|
||||||
|
//two lines.
|
||||||
|
setFixedSize( QSize( rect.width() + 20, rect.height()*2 + 20 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GetKey::x11Event( XEvent* e )
|
||||||
|
{
|
||||||
|
//keep Qt from closing the dialog upon seeing Esc pressed.
|
||||||
|
if (e->type == KeyPress) return true;
|
||||||
|
|
||||||
|
//On a key press, return the key and quit
|
||||||
|
//Ctrl+X == [No Key]
|
||||||
|
if (e->type == KeyRelease) {
|
||||||
|
if (XKeycodeToKeysym(display,e->xkey.keycode,0) == XK_x ) {
|
||||||
|
if (e->xkey.state & ControlMask) done( 0 );
|
||||||
|
else done( e->xkey.keycode );
|
||||||
|
}
|
||||||
|
else done( e->xkey.keycode );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//if we're accepting mouse clicks and a mouse button was clicked...
|
||||||
|
if (mouse && e->type == ButtonRelease) {
|
||||||
|
done ( e->xbutton.button + MOUSE_OFFSET);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//any other events we will pass on to the dialog. This allows for closing
|
||||||
|
//the window and easy redrawing :)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GetKey::paintEvent ( QPaintEvent * ) {
|
||||||
|
//whenever we need to repaint, draw in our text.
|
||||||
|
QPainter paint( this );
|
||||||
|
paint.drawText( rect(), AlignCenter, Text );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
KeyButton::KeyButton( QString name, int val, QWidget* parent, bool m, bool nowMouse)
|
KeyButton::KeyButton( QString name, int val, QWidget* parent, bool m, bool nowMouse)
|
||||||
:QPushButton(nowMouse?"Mouse " + QString::number(val):QString(ktos(val)), parent) {
|
:QPushButton(nowMouse?"Mouse " + QString::number(val):QString(ktos(val)), parent) {
|
||||||
mouse = m;
|
mouse = m;
|
||||||
mouseClicked = nowMouse;
|
mouseClicked = nowMouse;
|
||||||
buttonname = name;
|
buttonname = name;
|
||||||
value = val;
|
value = val;
|
||||||
connect( this, SIGNAL( clicked() ), SLOT( onClick() ));
|
connect( this, SIGNAL( clicked() ), SLOT( onClick() ));
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyButton::onClick() {
|
void KeyButton::onClick() {
|
||||||
//when clicked, ask for a key!
|
//when clicked, ask for a key!
|
||||||
value = GetKey( buttonname, mouse ).exec();
|
value = GetKey( buttonname, mouse ).exec();
|
||||||
//if the return value was a mouse click...
|
//if the return value was a mouse click...
|
||||||
if (value > MOUSE_OFFSET) {
|
if (value > MOUSE_OFFSET) {
|
||||||
mouseClicked = true;
|
mouseClicked = true;
|
||||||
value -= MOUSE_OFFSET;
|
value -= MOUSE_OFFSET;
|
||||||
setText( "Mouse " + QString::number(value));
|
setText( "Mouse " + QString::number(value));
|
||||||
}
|
}
|
||||||
//otherwise, it was a key press!
|
//otherwise, it was a key press!
|
||||||
else {
|
else {
|
||||||
mouseClicked = false;
|
mouseClicked = false;
|
||||||
setText( ktos(value));
|
setText( ktos(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,21 @@
|
|||||||
#define KEYCODE_H
|
#define KEYCODE_H
|
||||||
|
|
||||||
//To create the "press a key" dialog:
|
//To create the "press a key" dialog:
|
||||||
#include <QPushButton>
|
#include <qdialog.h>
|
||||||
#include <QDialog>
|
#include <qpainter.h>
|
||||||
#include <QPaintEvent>
|
|
||||||
#include <QPainter>
|
|
||||||
|
|
||||||
|
//For the KeyButton widget
|
||||||
|
#include <qpushbutton.h>
|
||||||
|
|
||||||
|
//For converting X Windows key names to something nicer.
|
||||||
|
#include <qregexp.h>
|
||||||
|
|
||||||
|
//Defines constants needed for x11Event
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
//The KeySym for "x"
|
||||||
|
#define XK_x 0x078
|
||||||
|
|
||||||
|
#define MOUSE_OFFSET 400
|
||||||
|
|
||||||
#include "constant.h"
|
#include "constant.h"
|
||||||
|
|
||||||
@ -16,6 +26,23 @@ const QString ktos( int keycode );
|
|||||||
//The X11 display, taken from main.cpp
|
//The X11 display, taken from main.cpp
|
||||||
extern Display* display;
|
extern Display* display;
|
||||||
|
|
||||||
|
//a keycode dialog box
|
||||||
|
class GetKey : public QDialog {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
GetKey( QString button, bool m = false );
|
||||||
|
protected:
|
||||||
|
//to filter through every event this thing sees, before QT does.
|
||||||
|
bool x11Event( XEvent* e );
|
||||||
|
//to avoid focus issues, there is only the dialog widget, all the
|
||||||
|
//rest is painted on. So, I need to know when to repaint.
|
||||||
|
void paintEvent ( QPaintEvent * );
|
||||||
|
private:
|
||||||
|
//the dialog's message
|
||||||
|
QString Text;
|
||||||
|
//does this dialog accept mouse clicks?
|
||||||
|
bool mouse;
|
||||||
|
};
|
||||||
|
|
||||||
//a button that requests a keycode from the user when clicked.
|
//a button that requests a keycode from the user when clicked.
|
||||||
class KeyButton : public QPushButton {
|
class KeyButton : public QPushButton {
|
||||||
|
551
src/layout.cpp
551
src/layout.cpp
@ -1,390 +1,301 @@
|
|||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
//initialize things and set up an icon :)
|
//initialize things and set up an icon :)
|
||||||
LayoutManager::LayoutManager( bool useTrayIcon ) {
|
LayoutManager::LayoutManager( bool useTrayIcon ) {
|
||||||
//no LayoutEdit yet.
|
//no LayoutEdit yet.
|
||||||
le = NULL;
|
le = NULL;
|
||||||
|
|
||||||
//prepare the popup first.
|
//prepare the popup first.
|
||||||
Popup = new QMenu();
|
Popup = new QPopupMenu();
|
||||||
fillPopup();
|
fillPopup();
|
||||||
connect(Popup,SIGNAL(triggered(QAction*)),this, SLOT(trayMenu(QAction*)));
|
connect(Popup,SIGNAL(activated(int)),this, SLOT(trayMenu(int)));
|
||||||
|
|
||||||
//make a tray icon
|
//make a tray icon
|
||||||
if (useTrayIcon) {
|
if (useTrayIcon) {
|
||||||
TrayIcon* Tray = new TrayIcon(QPixmap(ICON24),NAME,Popup,0,"tray");
|
TrayIcon* Tray = new TrayIcon(QPixmap(ICON24),NAME,Popup,0,"tray");
|
||||||
connect(Tray, SIGNAL( clicked(const QPoint&, int)), this, SLOT( trayClick()));
|
connect(Tray, SIGNAL( clicked(const QPoint&, int)), this, SLOT( trayClick()));
|
||||||
Tray->show();
|
Tray->show();
|
||||||
}
|
}
|
||||||
//or make a floating icon
|
//or make a floating icon
|
||||||
else {
|
else {
|
||||||
FloatingIcon* Icon = new FloatingIcon(QPixmap(ICON64),Popup,0,"tray");
|
FloatingIcon* Icon = new FloatingIcon(QPixmap(ICON64),Popup,0,"tray");
|
||||||
connect(Icon, SIGNAL( clicked()), this, SLOT( trayClick()));
|
connect(Icon, SIGNAL( clicked()), this, SLOT( trayClick()));
|
||||||
connect(Icon, SIGNAL( closed()), qApp, SLOT( quit()));
|
connect(Icon, SIGNAL( closed()), qApp, SLOT( quit()));
|
||||||
Icon->show();
|
Icon->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
//no layout loaded at start.
|
//no layout loaded at start.
|
||||||
setLayoutName(NL);
|
setLayoutName(NL);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LayoutManager::getFileName( QString layoutname ) {
|
QString LayoutManager::getFileName( QString layoutname ) {
|
||||||
return settingsDir + layoutname + ".lyt";
|
return settingsDir + layoutname + ".lyt";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LayoutManager::load(const QString& name) {
|
bool LayoutManager::load(const QString& name) {
|
||||||
//it's VERY easy to load NL :)
|
//it's VERY easy to load NL :)
|
||||||
if (name == NL) {
|
if (name == NL) {
|
||||||
clear();
|
clear();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
QFile file(getFileName(name));
|
QFile file(getFileName(name));
|
||||||
|
|
||||||
//if the file isn't available,
|
//if the file isn't available,
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
error("Load error","Failed to find a layout named " + name);
|
error("Load error","Failed to find a layout named " + name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if the file isn't readable,
|
//if the file isn't readable,
|
||||||
if (!file.open(QIODevice::ReadOnly)) {
|
if (!file.open(IO_ReadOnly)) {
|
||||||
error("Load error","Error reading from file " + file.fileName());
|
error("Load error","Error reading from file " + file.name());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//reset all the joypads.
|
//reset all the joypads.
|
||||||
//note that we don't use available here, but joypads instead. This is so
|
//note that we don't use available here, but joypads instead. This is so
|
||||||
//if one layout has more joypads than this one does, this won't have the
|
//if one layout has more joypads than this one does, this won't have the
|
||||||
//extra settings left over after things are supposed to be "cleared"
|
//extra settings left over after things are supposed to be "cleared"
|
||||||
QHashIterator<int, JoyPad*> it( joypads );
|
QIntDictIterator<JoyPad> it( joypads );
|
||||||
while (it.hasNext())
|
for ( ; it.current(); ++it ) {
|
||||||
{
|
it.current()->toDefault();
|
||||||
it.next();
|
}
|
||||||
it.value()->toDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
//start reading joypads!
|
//start reading joypads!
|
||||||
QTextStream stream( &file );
|
QTextStream stream( &file );
|
||||||
QString input = stream.readLine().toLower();
|
QString input = stream.readLine().lower();
|
||||||
QRegExp quoted("\"(.*)\"");
|
QRegExp quoted("\"(.*)\"");
|
||||||
bool okay;
|
bool okay;
|
||||||
int num;
|
int num;
|
||||||
|
|
||||||
while (input != QString::null) {
|
while (input != QString::null) {
|
||||||
QStringList words = input.split(" ");
|
QStringList words = QStringList::split(" ",input);
|
||||||
//if this line is specifying a joystick
|
//if this line is specifying a joystick
|
||||||
if (words[0] == "joystick") {
|
if (words[0] == "joystick") {
|
||||||
num = words[1].toInt(&okay);
|
num = words[1].toInt(&okay);
|
||||||
//make sure the number of the joystick is valid
|
//make sure the number of the joystick is valid
|
||||||
if (!okay || okay < 1) {
|
if (!okay || okay < 1) {
|
||||||
error( "Load error", "Error reading joystick definition. Expected: Joysyick 1 {");
|
error( "Load error", "Error reading joystick definition. Expected: Joysyick 1 {");
|
||||||
if (name != CurrentLayout) reload();
|
if (name != CurrentLayout) reload();
|
||||||
else clear();
|
else clear();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//if there was no joypad defined for this index before, make it now!
|
//if there was no joypad defined for this index before, make it now!
|
||||||
if (joypads[num-1] == 0) {
|
if (joypads[num-1] == 0) {
|
||||||
joypads.insert(num-1, new JoyPad(num-1, 0));
|
joypads.insert(num-1, new JoyPad(num-1, 0));
|
||||||
}
|
}
|
||||||
//try to read the joypad, report error on fail.
|
//try to read the joypad, report error on fail.
|
||||||
if (!joypads[num-1]->readConfig(&stream)) {
|
if (!joypads[num-1]->read(&stream)) {
|
||||||
error( "Load error", "Error reading definition for joystick " + QString::number(num-1));
|
error( "Load error", "Error reading definition for joystick " + QString::number(num-1));
|
||||||
//if this was attempting to change to a new layout and it failed,
|
//if this was attempting to change to a new layout and it failed,
|
||||||
//revert back to the old layout.
|
//revert back to the old layout.
|
||||||
if (name != CurrentLayout) reload();
|
if (name != CurrentLayout) reload();
|
||||||
//to keep from going into an infinite loop, if there is no good
|
//to keep from going into an infinite loop, if there is no good
|
||||||
//layout to fall back on, go to NL.
|
//layout to fall back on, go to NL.
|
||||||
else clear();
|
else clear();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//read a new line.
|
//read a new line.
|
||||||
input = stream.readLine().toLower();
|
input = stream.readLine().lower();
|
||||||
}
|
}
|
||||||
//if loading succeeded, this is our new layout.
|
//if loading succeeded, this is our new layout.
|
||||||
setLayoutName(name);
|
setLayoutName(name);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LayoutManager::load() {
|
bool LayoutManager::load() {
|
||||||
//try to load the file named "layout" to retrieve the last used layout name
|
//try to load the file named "layout" to retrieve the last used layout name
|
||||||
QFile file( settingsDir + "layout");
|
QFile file( settingsDir + "layout");
|
||||||
QString name;
|
QString name;
|
||||||
if (file.open(QIODevice::ReadOnly)) {
|
if (file.open(IO_ReadOnly)) {
|
||||||
QTextStream stream(&file);
|
QTextStream stream(&file);
|
||||||
name = stream.readLine();
|
name = stream.readLine();
|
||||||
file.close();
|
file.close();
|
||||||
//if there was no name, don't load.
|
//if there was no name, don't load.
|
||||||
if (name == "") {
|
if (name == "") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//if there was a name, try to load it! Note, this will still return
|
//if there was a name, try to load it! Note, this will still return
|
||||||
//false if the name is invalid ( see load() )
|
//false if the name is invalid ( see load() )
|
||||||
return load(name);
|
return load(name);
|
||||||
}
|
}
|
||||||
//if the file isn't available to open, don't load.
|
//if the file isn't available to open, don't load.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LayoutManager::reload() {
|
bool LayoutManager::reload() {
|
||||||
return load(CurrentLayout);
|
return load(CurrentLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutManager::clear() {
|
void LayoutManager::clear() {
|
||||||
//reset all the joypads...
|
//reset all the joypads...
|
||||||
QHashIterator<int, JoyPad*> it (joypads);
|
for (QIntDictIterator<JoyPad> it(joypads); it.current(); ++it) {
|
||||||
while (it.hasNext())
|
it.current()->toDefault();
|
||||||
{
|
}
|
||||||
it.next();
|
//and call our layout NL
|
||||||
it.value()->toDefault();
|
setLayoutName(NL);
|
||||||
}
|
|
||||||
//and call our layout NL
|
|
||||||
setLayoutName(NL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutManager::save() {
|
void LayoutManager::save() {
|
||||||
if (CurrentLayout == NL) {
|
if (CurrentLayout == NL) {
|
||||||
saveAs();
|
saveAs();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//get a filename
|
//get a filename
|
||||||
QString filename = getFileName( CurrentLayout );
|
QString filename = getFileName( CurrentLayout );
|
||||||
QFile file(filename);
|
QFile file(filename);
|
||||||
//if it's good, start writing the file
|
//if it's good, start writing the file
|
||||||
if (file.open(QIODevice::WriteOnly)) {
|
if (file.open(IO_WriteOnly)) {
|
||||||
QTextStream stream( &file );
|
QTextStream stream( &file );
|
||||||
stream << "# "NAME" Layout File\n\n";
|
stream << "# "NAME" Layout File\n\n";
|
||||||
QHashIterator<int, JoyPad*> it (joypads);
|
for (QIntDictIterator<JoyPad> it(joypads); it.current(); ++it) {
|
||||||
while (it.hasNext())
|
it.current()->write( &stream );
|
||||||
{
|
}
|
||||||
it.next();
|
file.close();
|
||||||
it.value()->write( &stream );
|
}
|
||||||
}
|
//if it's not, error.
|
||||||
file.close();
|
else
|
||||||
}
|
error("Save error", "Could not open file " + filename + ", layout not saved.");
|
||||||
//if it's not, error.
|
|
||||||
else
|
|
||||||
error("Save error", "Could not open file " + filename + ", layout not saved.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LayoutManager::saveAs() {
|
void LayoutManager::saveAs() {
|
||||||
bool ok;
|
bool ok;
|
||||||
//request a new name!
|
//request a new name!
|
||||||
QString name = QInputDialog::getText(0, NAME" - Name new layout","Enter a name for the new layout:", QLineEdit::Normal, QString::null, &ok );
|
QString name = QInputDialog::getText(NAME" - Name new layout","Enter a name for the new layout:", QLineEdit::Normal, QString::null, &ok );
|
||||||
if (!ok) {
|
if (!ok) return;
|
||||||
return;
|
QFile file(settingsDir + name + ".lyt");
|
||||||
}
|
//don't overwrite an existing layout.
|
||||||
QFile file(settingsDir + name + ".lyt");
|
if (file.exists()) {
|
||||||
//don't overwrite an existing layout.
|
error("Save error", "That name's already taken!");
|
||||||
if (file.exists()) {
|
return;
|
||||||
error("Save error", "That name's already taken!");
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//now that the new layout has a name, that is the name we should use.
|
//now that the new layout has a name, that is the name we should use.
|
||||||
setLayoutName(name);
|
setLayoutName(name);
|
||||||
|
|
||||||
//since we have a new name for this layout now, we can save it normally :)
|
//since we have a new name for this layout now, we can save it normally :)
|
||||||
save();
|
save();
|
||||||
|
|
||||||
//add the new name to our lists
|
//add the new name to our lists
|
||||||
fillPopup();
|
fillPopup();
|
||||||
if (le != NULL) {
|
if (le != NULL) {
|
||||||
le->updateLayoutList();
|
le->updateLayoutList();
|
||||||
}
|
}
|
||||||
printf("returning, user provided input\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutManager::saveDefault() {
|
void LayoutManager::saveDefault() {
|
||||||
QFile file( settingsDir + "layout");
|
QFile file( settingsDir + "layout");
|
||||||
if (file.open(QIODevice::WriteOnly)) {
|
if (file.open(IO_WriteOnly)) {
|
||||||
QTextStream stream(&file);
|
QTextStream stream(&file);
|
||||||
stream << CurrentLayout;
|
stream << CurrentLayout;
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutManager::remove() {
|
void LayoutManager::remove() {
|
||||||
if (CurrentLayout == NL) return;
|
if (CurrentLayout == NL) return;
|
||||||
if (QMessageBox::warning( 0, NAME" - Delete layout?","Remove layout permanently from your hard drive?", "Yes", "No", 0, 0, 1 ) == 1) return;
|
if (QMessageBox::warning( 0, NAME" - Delete layout?","Remove layout permanently from your hard drive?", "Yes", "No", 0, 0, 1 ) == 1) return;
|
||||||
QString filename = getFileName( CurrentLayout );
|
QString filename = getFileName( CurrentLayout );
|
||||||
if (!QFile(filename).remove()) {
|
if (!QFile(filename).remove()) {
|
||||||
error("Remove error", "Could not remove file " + filename);
|
error("Remove error", "Could not remove file " + filename);
|
||||||
}
|
}
|
||||||
fillPopup();
|
fillPopup();
|
||||||
|
|
||||||
if (le != NULL) {
|
if (le != NULL) {
|
||||||
le->updateLayoutList();
|
le->updateLayoutList();
|
||||||
}
|
}
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList LayoutManager::getLayoutNames() {
|
QStringList LayoutManager::getLayoutNames() {
|
||||||
//goes through the list of .lyt files and removes the file extensions ;)
|
//goes through the list of .lyt files and removes the file extensions ;)
|
||||||
QStringList result = QDir(settingsDir).entryList(QStringList("*.lyt"));
|
QStringList result = QDir(settingsDir).entryList("*.lyt");
|
||||||
|
|
||||||
for ( QStringList::Iterator it = result.begin(); it != result.end(); ++it ) {
|
for ( QStringList::Iterator it = result.begin(); it != result.end(); ++it ) {
|
||||||
*it = (*it).left((*it).length() - 4);
|
*it = (*it).left((*it).length() - 4);
|
||||||
}
|
}
|
||||||
//and, of course, there's always NL.
|
//and, of course, there's always NL.
|
||||||
result.prepend(NL);
|
result.prepend(NL);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutManager::setLayoutName(QString name) {
|
void LayoutManager::setLayoutName(QString name) {
|
||||||
CurrentLayout = name;
|
CurrentLayout = name;
|
||||||
fillPopup();
|
fillPopup();
|
||||||
|
|
||||||
if (le != NULL) {
|
if (le != NULL) {
|
||||||
le->setLayout(name);
|
le->setLayout(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void LayoutManager::trayClick() {
|
void LayoutManager::trayClick() {
|
||||||
//don't show the dialog if there aren't any joystick devices plugged in
|
//don't show the dialog if there aren't any joystick devices plugged in
|
||||||
if (available.count() == 0) {
|
if (available.count() == 0) {
|
||||||
error("No joystick devices available","No joystick devices are currently available to configure.\nPlease plug in a gaming device and select\n\"Update Joystick Devices\" from the popup menu.");
|
error("No joystick devices available","No joystick devices are currently available to configure.\nPlease plug in a gaming device and select\n\"Update Joystick Devices\" from the popup menu.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//otherwise, make a new LayoutEdit dialog and show it.
|
//otherwise, make a new LayoutEdit dialog and show it.
|
||||||
le = new LayoutEdit(this);
|
le = new LayoutEdit(this);
|
||||||
le->setLayout(CurrentLayout);
|
le->setLayout(CurrentLayout);
|
||||||
//note, this will cause the menu to hang. You cannot use the menu while the
|
//note, this will cause the menu to hang. You cannot use the menu while the
|
||||||
//dialog is active. I'd rather it not work out that way, but this makes my
|
//dialog is active. I'd rather it not work out that way, but this makes my
|
||||||
//code MUCH simpler for a small inconvenience that shouldn't matter. For
|
//code MUCH simpler for a small inconvenience that shouldn't matter. For
|
||||||
//instance, I don't have to worry about the current joysticks changing
|
//instance, I don't have to worry about the current joysticks changing
|
||||||
//while there's a dialog and therefore adjusting the dialog to match.
|
//while there's a dialog and therefore adjusting the dialog to match.
|
||||||
le->exec();
|
le->exec();
|
||||||
delete le;
|
delete le;
|
||||||
le = NULL;
|
le = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutManager::trayMenu(QAction *menuItemAction) {
|
void LayoutManager::trayMenu(int id) {
|
||||||
//if they clicked on a Layout name, load it!
|
//if they clicked on a Layout name, load it!
|
||||||
//note that the other options are handled with their own special functions
|
//note that the other options are handled with their own special functions
|
||||||
printf("%s\n", qPrintable(menuItemAction->text()));
|
if (Popup->indexOf(id) > 4 && Popup->text(id) != "Quit") {
|
||||||
printf("oh hi\n");
|
load(Popup->text(id));
|
||||||
//printf("%d\n", Popup->
|
}
|
||||||
if (Popup->actions().indexOf(menuItemAction) > 1 && menuItemAction->text() != "Quit" &&
|
|
||||||
menuItemAction->text() != "Update lyaout list" &&
|
|
||||||
menuItemAction->text() != "Update joystick devices") {
|
|
||||||
load(menuItemAction->text());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutManager::fillPopup() {
|
void LayoutManager::fillPopup() {
|
||||||
printf("starting fillPopup\n");
|
//start with an empty slate
|
||||||
//start with an empty slate
|
Popup->clear();
|
||||||
Popup->clear();
|
|
||||||
|
|
||||||
//make a list of joystick devices
|
//make a list of joystick devices
|
||||||
QString devs = "Joysticks: ";
|
QString devs = "Joysticks: ";
|
||||||
QHashIterator<int, JoyPad*> it( available );
|
QIntDictIterator<JoyPad> it( available );
|
||||||
while (it.hasNext())
|
for ( ; it.current(); ++it ) {
|
||||||
{
|
devs += QString::number(it.currentKey() + 1) + " ";
|
||||||
it.next();
|
}
|
||||||
devs += QString::number(it.key() + 1) + " ";
|
Popup->insertItem(devs);
|
||||||
}
|
Popup->insertSeparator();
|
||||||
QAction *temp = Popup->addAction(devs);
|
|
||||||
Popup->addSeparator(/*temp*/);
|
|
||||||
|
|
||||||
//add in the Update options
|
//add in the Update options
|
||||||
QAction *tempAdd = new QAction("Update layout list", this);
|
Popup->insertItem("Update layout list", this, SLOT(fillPopup()));
|
||||||
connect(tempAdd, SIGNAL(triggered(bool)), this, SLOT(fillPopup()));
|
Popup->insertItem("Update joystick devices", this, SLOT(updateJoyDevs()));
|
||||||
Popup->addAction(tempAdd);
|
Popup->insertSeparator();
|
||||||
tempAdd = new QAction("Update joystick devices", this);
|
|
||||||
connect(tempAdd, SIGNAL(triggered(bool)), this, SLOT(updateJoyDevs()));
|
|
||||||
Popup->addAction(tempAdd);
|
|
||||||
Popup->addSeparator(/*temp*/);
|
|
||||||
|
|
||||||
//then add all the layout names
|
//then add all the layout names
|
||||||
QStringList names = getLayoutNames();
|
QStringList names = getLayoutNames();
|
||||||
for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) {
|
for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) {
|
||||||
temp = Popup->addAction(*it);
|
int id = Popup->insertItem(*it);
|
||||||
temp->setCheckable(true);
|
//put a check by the current one ;)
|
||||||
//put a check by the current one ;)
|
if (CurrentLayout == (*it)) Popup->setItemChecked(id,true);
|
||||||
if (CurrentLayout == (*it)) {
|
}
|
||||||
temp->setChecked(true);
|
Popup->insertSeparator();
|
||||||
}
|
|
||||||
}
|
|
||||||
Popup->addSeparator();
|
|
||||||
|
|
||||||
//and, at the end, quit!
|
//and, at the end, quit!
|
||||||
Popup->addAction("Quit",qApp,SLOT(quit()));
|
Popup->insertItem("Quit",qApp,SLOT(quit()));
|
||||||
printf("returning from fill popup\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutManager::updateJoyDevs() {
|
void LayoutManager::updateJoyDevs() {
|
||||||
printf("entering update JoyDevs\n");
|
//the actual update process is handled by main.cpp, we just need to signal
|
||||||
QString devdir = DEVDIR;
|
//ourselves to do it.
|
||||||
//reset all joydevs to sentinal value (-1)
|
raise(SIGUSR1);
|
||||||
do {
|
|
||||||
QHashIterator<int, JoyPad*> it( joypads );
|
|
||||||
while (it.hasNext() ) {
|
|
||||||
it.next();
|
|
||||||
it.value()->unsetDev();
|
|
||||||
}
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
//clear out the list of previously available joysticks
|
|
||||||
available.clear();
|
|
||||||
|
|
||||||
//set all joydevs anew (create new JoyPad's if necesary)
|
|
||||||
QDir DeviceDir(devdir);
|
|
||||||
QStringList devices = DeviceDir.entryList(QStringList("js*"), QDir::System );
|
|
||||||
QRegExp devicename(".*\\js(\\d+)");
|
|
||||||
int joydev;
|
|
||||||
int index;
|
|
||||||
//for every joystick device in the directory listing...
|
|
||||||
//(note, with devfs, only available devices are listed)
|
|
||||||
for (QStringList::Iterator it = devices.begin(); it != devices.end(); ++it) {
|
|
||||||
//try opening the device.
|
|
||||||
printf("%s\n", qPrintable(devdir + "/" + (*it)));
|
|
||||||
joydev = open( qPrintable(devdir + "/" + (*it)), O_RDONLY | O_NONBLOCK);
|
|
||||||
//if it worked, then we have a live joystick! Make sure it's properly
|
|
||||||
//setup.
|
|
||||||
if (joydev > 0) {
|
|
||||||
printf("joystick found, constructing...\n");
|
|
||||||
devicename.indexIn(*it);
|
|
||||||
index = QString(devicename.cap(1)).toInt();
|
|
||||||
JoyPad* joypad;
|
|
||||||
//if we've never seen this device before, make a new one!
|
|
||||||
if (joypads[index] == 0) {
|
|
||||||
struct pollfd read_struct;
|
|
||||||
read_struct.fd = joydev;
|
|
||||||
read_struct.events = POLLIN;
|
|
||||||
char buf[10];
|
|
||||||
while(poll(&read_struct, 1, 2)!=0) {
|
|
||||||
printf("reading junk data\n");
|
|
||||||
read(joydev, buf, 10);
|
|
||||||
}
|
|
||||||
joypad = new JoyPad( index, joydev );
|
|
||||||
joypads.insert(index,joypad);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf("resetting to dev...\n");
|
|
||||||
joypad = joypads[index];
|
|
||||||
joypad->resetToDev(joydev);
|
|
||||||
}
|
|
||||||
//make this joystick device available.
|
|
||||||
available.insert(index,joypad);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
int errsv = errno;
|
|
||||||
printf("well fuck!\n");
|
|
||||||
printf("%s\n", strerror(errsv));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("done rebuilding joystick devices\n");
|
|
||||||
//when it's all done, rebuild the popup menu so it displays the correct
|
|
||||||
//information.
|
|
||||||
fillPopup();
|
|
||||||
//the actual update process is handled by main.cpp, we just need to signal
|
|
||||||
//ourselves to do it.
|
|
||||||
//raise(SIGUSR1);
|
|
||||||
printf("returning from rebuild function\n");
|
|
||||||
}
|
}
|
||||||
|
30
src/layout.h
30
src/layout.h
@ -1,6 +1,22 @@
|
|||||||
#ifndef JOY_LAYOUT_H
|
#ifndef JOY_LAYOUT_H
|
||||||
#define JOY_LAYOUT_H
|
#define JOY_LAYOUT_H
|
||||||
|
|
||||||
|
//for file i/o
|
||||||
|
#include <qdir.h>
|
||||||
|
#include <qfile.h>
|
||||||
|
#include <qtextstream.h>
|
||||||
|
#include <qstringlist.h>
|
||||||
|
|
||||||
|
//to get a name for a new layout
|
||||||
|
#include <qinputdialog.h>
|
||||||
|
|
||||||
|
//qpopup is a REAL pain to include ;) This is because of some
|
||||||
|
//odd complications and reciprocalities in QT... unfortunately, this is the
|
||||||
|
//best way I've found to get around it.
|
||||||
|
#ifndef MAIN
|
||||||
|
//the layout manager is responsible for the tray icon and its popup
|
||||||
|
#include <qpopupmenu.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
//to allow for interprocess communications (ie, signaling a running instance of
|
//to allow for interprocess communications (ie, signaling a running instance of
|
||||||
//qjoypad by running "qjoypad layout-name", etc.) QJoyPad uses signals to
|
//qjoypad by running "qjoypad layout-name", etc.) QJoyPad uses signals to
|
||||||
@ -8,14 +24,6 @@
|
|||||||
//the joystick device list.
|
//the joystick device list.
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include <QAction>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QMenu>
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QDialog>
|
|
||||||
#include <QInputDialog>
|
|
||||||
#include <poll.h>
|
|
||||||
|
|
||||||
//a layout handles several joypads
|
//a layout handles several joypads
|
||||||
#include "joypad.h"
|
#include "joypad.h"
|
||||||
//for errors
|
//for errors
|
||||||
@ -33,7 +41,7 @@
|
|||||||
#define NL "[NO LAYOUT]"
|
#define NL "[NO LAYOUT]"
|
||||||
|
|
||||||
//where QJoyPad saves its settings!
|
//where QJoyPad saves its settings!
|
||||||
const QString settingsDir(QDir::homePath() + "/.qjoypad3/");
|
const QString settingsDir(QDir::homeDirPath() + "/.qjoypad3/");
|
||||||
|
|
||||||
//handles loading, saving, and changing of layouts
|
//handles loading, saving, and changing of layouts
|
||||||
class LayoutManager : public QObject {
|
class LayoutManager : public QObject {
|
||||||
@ -66,7 +74,7 @@ class LayoutManager : public QObject {
|
|||||||
//when the tray icon is clicked
|
//when the tray icon is clicked
|
||||||
void trayClick();
|
void trayClick();
|
||||||
//when the user selects an item on the tray's popup menu
|
//when the user selects an item on the tray's popup menu
|
||||||
void trayMenu(QAction* menuItemAction);
|
void trayMenu(int id);
|
||||||
//rebuild the popup menu with the current information
|
//rebuild the popup menu with the current information
|
||||||
void fillPopup();
|
void fillPopup();
|
||||||
//update the list of available joystick devices
|
//update the list of available joystick devices
|
||||||
@ -79,7 +87,7 @@ class LayoutManager : public QObject {
|
|||||||
//the layout that is currently in use
|
//the layout that is currently in use
|
||||||
QString CurrentLayout;
|
QString CurrentLayout;
|
||||||
//the popup menu from the tray/floating icon
|
//the popup menu from the tray/floating icon
|
||||||
QMenu* Popup;
|
QPopupMenu* Popup;
|
||||||
|
|
||||||
//if there is a LayoutEdit open, this points to it. Otherwise, NULL.
|
//if there is a LayoutEdit open, this points to it. Otherwise, NULL.
|
||||||
LayoutEdit* le;
|
LayoutEdit* le;
|
||||||
|
@ -1,132 +1,110 @@
|
|||||||
#include "layout_edit.h"
|
#include "layout_edit.h"
|
||||||
|
|
||||||
|
|
||||||
//build the dialog
|
//build the dialog
|
||||||
LayoutEdit::LayoutEdit( LayoutManager* l ) {
|
LayoutEdit::LayoutEdit( LayoutManager* l ) {
|
||||||
lm = l;
|
lm = l;
|
||||||
|
|
||||||
setWindowTitle( NAME );
|
setCaption( NAME );
|
||||||
setWindowIcon(QPixmap(ICON24));
|
setIcon(QPixmap(ICON24));
|
||||||
|
|
||||||
LMain = new QVBoxLayout( this);
|
LMain = new QVBoxLayout( this,5,5 );
|
||||||
LMain->setSpacing(5);
|
|
||||||
LMain->setMargin(5);
|
|
||||||
|
|
||||||
QFrame* frame = new QFrame(this);
|
QFrame* frame = new QFrame(this);
|
||||||
frame->setFrameStyle(QFrame::Box | QFrame::Sunken );
|
frame->setFrameStyle(QFrame::Box | QFrame::Sunken );
|
||||||
QGridLayout* g = new QGridLayout(frame);
|
QGridLayout* g = new QGridLayout(frame,2,1,5,5);
|
||||||
g->setMargin(5);
|
CLayouts = new QComboBox(frame);
|
||||||
g->setSpacing(5);
|
connect( CLayouts, SIGNAL(activated( const QString& )), lm, SLOT(load(const QString&)));
|
||||||
CLayouts = new QComboBox(frame);
|
g->addMultiCellWidget(CLayouts,0,0,0,3);
|
||||||
connect( CLayouts, SIGNAL(activated( const QString& )), lm, SLOT(load(const QString&)));
|
|
||||||
g->addWidget(CLayouts,0,0,1,4);
|
|
||||||
|
|
||||||
//most of these buttons can link directly into slots in the LayoutManager
|
//most of these buttons can link directly into slots in the LayoutManager
|
||||||
BAdd = new QPushButton("Add", frame);
|
BAdd = new QPushButton("Add", frame);
|
||||||
connect(BAdd, SIGNAL(clicked()), lm, SLOT(saveAs()));
|
connect(BAdd, SIGNAL(clicked()), lm, SLOT(saveAs()));
|
||||||
g->addWidget(BAdd,1,0);
|
g->addWidget(BAdd,1,0);
|
||||||
BRem = new QPushButton("Remove", frame);
|
BRem = new QPushButton("Remove", frame);
|
||||||
connect(BRem, SIGNAL(clicked()), lm, SLOT(remove()));
|
connect(BRem, SIGNAL(clicked()), lm, SLOT(remove()));
|
||||||
g->addWidget(BRem,1,1);
|
g->addWidget(BRem,1,1);
|
||||||
BUpd = new QPushButton("Update", frame);
|
BUpd = new QPushButton("Update", frame);
|
||||||
connect(BUpd, SIGNAL(clicked()), lm, SLOT(save()));
|
connect(BUpd, SIGNAL(clicked()), lm, SLOT(save()));
|
||||||
g->addWidget(BUpd,1,2);
|
g->addWidget(BUpd,1,2);
|
||||||
BRev = new QPushButton("Revert", frame);
|
BRev = new QPushButton("Revert", frame);
|
||||||
connect(BRev, SIGNAL(clicked()), lm, SLOT(reload()));
|
connect(BRev, SIGNAL(clicked()), lm, SLOT(reload()));
|
||||||
g->addWidget(BRev,1,3);
|
g->addWidget(BRev,1,3);
|
||||||
LMain->addWidget( frame );
|
LMain->addWidget( frame );
|
||||||
|
|
||||||
//produce a list of names for the FlashRadioArray
|
//we have a WidgetStack to represent the multiple joypads
|
||||||
//this is only necesary since joystick devices need not always be
|
PadStack = new QWidgetStack( this );
|
||||||
//contiguous
|
PadStack->setFrameStyle(QFrame::Box | QFrame::Sunken );
|
||||||
int padcount = available.count();
|
LMain->addWidget(PadStack);
|
||||||
QString names[padcount];
|
|
||||||
int i = 0;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
QHashIterator<int, JoyPad*> it( available );
|
|
||||||
while (it.hasNext())
|
|
||||||
{
|
|
||||||
it.next();
|
|
||||||
names[i] = it.value()->getName();
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
//flash radio array
|
//produce a list of names for the FlashRadioArray
|
||||||
JoyButtons = new FlashRadioArray(padcount, names, true, this );
|
//this is only necesary since joystick devices need not always be
|
||||||
LMain->addWidget( JoyButtons );
|
//contiguous
|
||||||
|
int padcount = available.count();
|
||||||
|
QString names[padcount];
|
||||||
|
int i = 0;
|
||||||
|
QIntDictIterator<JoyPad> it( available );
|
||||||
|
for ( ; it.current(); ++it ) {
|
||||||
|
names[i] = it.current()->getName();
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
//we have a WidgetStack to represent the multiple joypads
|
//flash radio array
|
||||||
PadStack = new QStackedWidget( this );
|
JoyButtons = new FlashRadioArray(padcount, names, true, this );
|
||||||
PadStack->setFrameStyle(QFrame::Box | QFrame::Sunken );
|
LMain->insertWidget( 1, JoyButtons );
|
||||||
LMain->addWidget(PadStack);
|
|
||||||
|
|
||||||
//go through each of the available joysticks
|
//go through each of the available joysticks
|
||||||
i = 0; // i is the current index into PadStack
|
i = 0; // i is the current index into PadStack
|
||||||
do
|
for (it.toFirst() ; it.current(); ++it ) {
|
||||||
{
|
//add a new JoyPadWidget to the stack
|
||||||
QHashIterator<int, JoyPad*> it(available);
|
PadStack->addWidget( it.current()->widget(PadStack,i),i );
|
||||||
while (it.hasNext())
|
//every time it "flashes", flash the associated tab.
|
||||||
{
|
connect( PadStack->widget(i), SIGNAL( flashed( int ) ), JoyButtons, SLOT( flash( int )));
|
||||||
it.next();
|
++i;
|
||||||
//add a new JoyPadWidget to the stack
|
}
|
||||||
PadStack->insertWidget( i,it.value()->widget(PadStack,i) );
|
//whenever a new tab is selected, raise the appropriate JoyPadWidget
|
||||||
//every time it "flashes", flash the associated tab.
|
connect( JoyButtons, SIGNAL( changed( int ) ), PadStack, SLOT( raiseWidget( int )));
|
||||||
connect( PadStack->widget(i), SIGNAL( flashed( int ) ), JoyButtons, SLOT( flash( int )));
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
} while (0);
|
|
||||||
//whenever a new tab is selected, raise the appropriate JoyPadWidget
|
|
||||||
connect( JoyButtons, SIGNAL( changed( int ) ), PadStack, SLOT( setCurrentIndex( int )));
|
|
||||||
|
|
||||||
updateLayoutList();
|
updateLayoutList();
|
||||||
|
|
||||||
//add the buttons at the bottom.
|
//add the buttons at the bottom.
|
||||||
QHBoxLayout* h = new QHBoxLayout(0);
|
QHBoxLayout* h = new QHBoxLayout(0,0,5);
|
||||||
h->setMargin(0);
|
QPushButton* close = new QPushButton( "-- Close Dialog --", this );
|
||||||
h->setSpacing(5);
|
connect(close, SIGNAL(clicked()), this, SLOT(close()));
|
||||||
QPushButton* close = new QPushButton( "-- Close Dialog --", this );
|
h->addWidget(close);
|
||||||
connect(close, SIGNAL(clicked()), this, SLOT(close()));
|
QPushButton* quit = new QPushButton( "-- Quit --", this );
|
||||||
h->addWidget(close);
|
connect( quit, SIGNAL( clicked() ), qApp, SLOT(quit()));
|
||||||
QPushButton* quit = new QPushButton( "-- Quit --", this );
|
h->addWidget(quit);
|
||||||
connect( quit, SIGNAL( clicked() ), qApp, SLOT(quit()));
|
LMain->addLayout(h);
|
||||||
h->addWidget(quit);
|
|
||||||
LMain->addLayout(h);
|
|
||||||
blockEvents = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutEdit::setLayout(QString layout) {
|
void LayoutEdit::setLayout(QString layout) {
|
||||||
//change the text,
|
//change the text,
|
||||||
CLayouts->setItemText(CLayouts->currentIndex(), layout);
|
CLayouts->setCurrentText(layout);
|
||||||
//update all the JoyPadWidgets.
|
//update all the JoyPadWidgets.
|
||||||
for (uint i = 0; i < available.count(); i++) {
|
for (uint i = 0; i < available.count(); i++) {
|
||||||
((JoyPadWidget*)PadStack->widget(i))->update();
|
((JoyPadWidget*)PadStack->widget(i))->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutEdit::updateLayoutList() {
|
void LayoutEdit::updateLayoutList() {
|
||||||
//blank the list, then load in new names from the LayoutManager.
|
//blank the list, then load in new names from the LayoutManager.
|
||||||
CLayouts->clear();
|
CLayouts->clear();
|
||||||
QStringList layouts = lm->getLayoutNames();
|
QStringList layouts = lm->getLayoutNames();
|
||||||
//For some reason, insertStringList doesn't want to work for me!
|
//For some reason, insertStringList doesn't want to work for me!
|
||||||
for ( QStringList::Iterator it = layouts.begin(); it != layouts.end(); ++it ) {
|
for ( QStringList::Iterator it = layouts.begin(); it != layouts.end(); ++it ) {
|
||||||
CLayouts->insertItem(-1,*it);
|
CLayouts->insertItem(*it);
|
||||||
}
|
}
|
||||||
CLayouts->setItemText(CLayouts->currentIndex(), lm->CurrentLayout);
|
CLayouts->setCurrentText(lm->CurrentLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutEdit::windowActivationChange( bool oldActive ) {
|
void LayoutEdit::windowActivationChange( bool oldActive ) {
|
||||||
if (oldActive) return;
|
if (oldActive) return;
|
||||||
//whenever the window becomes active, release all pressed buttons! This way
|
|
||||||
//you don't get any presses without releases to confuse things.
|
//whenever the window becomes active, release all pressed buttons! This way
|
||||||
blockEvents = true;
|
//you don't get any presses without releases to confuse things.
|
||||||
QHashIterator<int, JoyPad*> it( available );
|
QIntDictIterator<JoyPad> it( available );
|
||||||
while (it.hasNext())
|
for ( ; it.current(); ++it ) {
|
||||||
{
|
it.current()->release();
|
||||||
printf("iterating and releasing\n");
|
}
|
||||||
it.next();
|
|
||||||
it.value()->release();
|
|
||||||
}
|
|
||||||
printf("done releasing!\n");
|
|
||||||
blockEvents = false;
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
#ifndef LAYOUT_EDIT_H
|
#ifndef LAYOUT_EDIT_H
|
||||||
#define LAYOUT_EDIT_H
|
#define LAYOUT_EDIT_H
|
||||||
|
|
||||||
#include <QStackedWidget>
|
//needed to build the dialog
|
||||||
|
#include <qdialog.h>
|
||||||
|
#include <qlayout.h>
|
||||||
|
#include <qcombobox.h>
|
||||||
|
#include <qwidgetstack.h>
|
||||||
|
|
||||||
//for the tab list of joypads
|
//for the tab list of joypads
|
||||||
#include "flash.h"
|
#include "flash.h"
|
||||||
@ -28,13 +32,15 @@ class LayoutEdit : public QDialog {
|
|||||||
|
|
||||||
//find out when the window is activated.
|
//find out when the window is activated.
|
||||||
virtual void windowActivationChange( bool oldActive );
|
virtual void windowActivationChange( bool oldActive );
|
||||||
bool blockEvents;
|
|
||||||
//parts of the dialog:
|
//parts of the dialog:
|
||||||
QVBoxLayout *LMain;
|
QVBoxLayout *LMain;
|
||||||
QStackedWidget *PadStack;
|
QWidgetStack *PadStack;
|
||||||
FlashRadioArray *JoyButtons;
|
FlashRadioArray *JoyButtons;
|
||||||
|
|
||||||
QComboBox* CLayouts;
|
QComboBox* CLayouts;
|
||||||
QPushButton *BAdd, *BRem, *BUpd, *BRev;
|
QPushButton *BAdd, *BRem, *BUpd, *BRev;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
65
src/loop.cpp
Normal file
65
src/loop.cpp
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#include "loop.h"
|
||||||
|
|
||||||
|
JoyLoop::JoyLoop() {
|
||||||
|
//I like to start from zero, though, in all honesty, this doesn't matter.
|
||||||
|
tick = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool JoyLoop::processEvents( ProcessEventsFlags ) {
|
||||||
|
//standard event processing, except we get to throw in a few things of
|
||||||
|
//our own!
|
||||||
|
|
||||||
|
int joydev;
|
||||||
|
JoyPad* pad;
|
||||||
|
js_event msg;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
//go through the currently plugged-in joysticks
|
||||||
|
QIntDictIterator<JoyPad> it( available );
|
||||||
|
for ( ; it.current(); ++it ) {
|
||||||
|
pad = it.current();
|
||||||
|
//get the file descriptor for the device
|
||||||
|
joydev = pad->joydev;
|
||||||
|
//and try reading an event, non-blocking
|
||||||
|
len = read( joydev, &msg, sizeof(js_event));
|
||||||
|
//if there was a real event waiting,
|
||||||
|
if (len == (int) sizeof(js_event)) {
|
||||||
|
//pass that event on to the joypad!
|
||||||
|
pad->jsevent(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//sleep for a moment. This is just to keep us from throwing all the
|
||||||
|
//available processer power into madly checking for new events.
|
||||||
|
usleep(1);
|
||||||
|
|
||||||
|
//now we can let QT process all of its events, like GUI events and timers.
|
||||||
|
return QEventLoop::processEvents(AllEvents);
|
||||||
|
}
|
||||||
|
|
||||||
|
void JoyLoop::takeTimer( Component* c ) {
|
||||||
|
//if this is the first Component asking for a timer, then we can start
|
||||||
|
//up the timer! It isn't running unless someone needs it.
|
||||||
|
if (timerList.isEmpty()) startTimer( MSEC );
|
||||||
|
//remember this Component so we can signal it.
|
||||||
|
timerList.append( c );
|
||||||
|
}
|
||||||
|
|
||||||
|
void JoyLoop::tossTimer( Component* c ) {
|
||||||
|
//forget that Component, it doesn't NEED us any more :(
|
||||||
|
timerList.remove( c );
|
||||||
|
//if that means there are no longer any Components listening for timer
|
||||||
|
//events, then we can go ahead and stop timing.
|
||||||
|
if (timerList.isEmpty()) killTimers();
|
||||||
|
}
|
||||||
|
|
||||||
|
void JoyLoop::timerEvent( QTimerEvent* ) {
|
||||||
|
//ever MSEC miliseconds...
|
||||||
|
|
||||||
|
//increment the counter (used for timing in axis.cpp and button.cpp)
|
||||||
|
++tick;
|
||||||
|
//and notify every Component in the list.
|
||||||
|
for ( Component* c = timerList.first(); c; c = timerList.next() ) {
|
||||||
|
c->timer(tick);
|
||||||
|
}
|
||||||
|
}
|
39
src/loop.h
Normal file
39
src/loop.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#ifndef JOY_LOOP_H
|
||||||
|
#define JOY_LOOP_H
|
||||||
|
|
||||||
|
//this is an event loop
|
||||||
|
#include <qeventloop.h>
|
||||||
|
|
||||||
|
//for reading events from the joysticks
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <linux/joystick.h>
|
||||||
|
|
||||||
|
//to pass events on to the joypads
|
||||||
|
#include "joypad.h"
|
||||||
|
//to know which devices need to be checked for joystick events
|
||||||
|
#include "device.h"
|
||||||
|
|
||||||
|
//A Component is either an Axis or a Button
|
||||||
|
class Component;
|
||||||
|
|
||||||
|
//the main event loop of QJoyPad; its main distinction from a regular event loop
|
||||||
|
//is that it reads joystick events on every iteration and also provides a timer
|
||||||
|
//to any Components that need it.
|
||||||
|
class JoyLoop : public QEventLoop {
|
||||||
|
public:
|
||||||
|
JoyLoop();
|
||||||
|
bool processEvents( ProcessEventsFlags );
|
||||||
|
//provide a timer to the requesting Component
|
||||||
|
void takeTimer( Component* c );
|
||||||
|
//stop providing a timer to the given Component
|
||||||
|
void tossTimer( Component* c );
|
||||||
|
protected:
|
||||||
|
//happens ever MSEC miliseconds :)
|
||||||
|
virtual void timerEvent( QTimerEvent* );
|
||||||
|
//just a counter, nothing more.
|
||||||
|
int tick;
|
||||||
|
//a list of the Components that need a timer
|
||||||
|
QPtrList<Component> timerList;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
367
src/main.cpp
367
src/main.cpp
@ -1,13 +1,22 @@
|
|||||||
#define MAIN
|
#define MAIN
|
||||||
|
|
||||||
//to create a qapplication
|
//to create a qapplication
|
||||||
#include <QFile>
|
#include <qapplication.h>
|
||||||
|
//for basic file i/o and argument parsing
|
||||||
|
#include <qstring.h>
|
||||||
|
#include <qdir.h>
|
||||||
|
#include <qfile.h>
|
||||||
|
#include <qstringlist.h>
|
||||||
|
#include <qregexp.h>
|
||||||
|
|
||||||
//for ouput when there is no GUI going
|
//for ouput when there is no GUI going
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
//to create and handle signals for various events
|
//to create and handle signals for various events
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
//for our custom-made event loop
|
||||||
|
#include "loop.h"
|
||||||
//to load layouts
|
//to load layouts
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
//to give event.h the current X11 display
|
//to give event.h the current X11 display
|
||||||
@ -16,14 +25,21 @@
|
|||||||
#include "device.h"
|
#include "device.h"
|
||||||
//to produce errors!
|
//to produce errors!
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include <QX11Info>
|
|
||||||
#include <poll.h>
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
//for making universally available variables
|
//for making universally available variables
|
||||||
extern Display* display; //from event.h
|
extern Display* display; //from event.h
|
||||||
QHash<int, JoyPad*> available; //to device.h
|
QIntDict<JoyPad> available; //to device.h
|
||||||
QHash<int, JoyPad*> joypads; //to device.h
|
QIntDict<JoyPad> joypads; //to device.h
|
||||||
|
QPtrList<Component> timerList; //to timer.h
|
||||||
|
|
||||||
|
//to be made available in timer.h
|
||||||
|
//they simply pass on the message to JoyLoop
|
||||||
|
void takeTimer( Component* c ) {
|
||||||
|
((JoyLoop*) qApp->eventLoop())->takeTimer( c );
|
||||||
|
}
|
||||||
|
void tossTimer( Component* c ) {
|
||||||
|
((JoyLoop*) qApp->eventLoop())->tossTimer( c );
|
||||||
|
}
|
||||||
|
|
||||||
//variables needed in various functions in this file
|
//variables needed in various functions in this file
|
||||||
LayoutManager* lm;
|
LayoutManager* lm;
|
||||||
@ -33,61 +49,49 @@ QString devdir = DEVDIR;
|
|||||||
|
|
||||||
//update the joystick devices!
|
//update the joystick devices!
|
||||||
void buildJoyDevices() {
|
void buildJoyDevices() {
|
||||||
//reset all joydevs to sentinal value (-1)
|
//reset all joydevs to sentinal value (-1)
|
||||||
do {
|
QIntDictIterator<JoyPad> it( joypads );
|
||||||
QHashIterator<int, JoyPad*> it( joypads );
|
for ( ; it.current(); ++it ) {
|
||||||
while (it.hasNext() ) {
|
it.current()->unsetDev();
|
||||||
it.next();
|
}
|
||||||
it.value()->unsetDev();
|
|
||||||
}
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
//clear out the list of previously available joysticks
|
//clear out the list of previously available joysticks
|
||||||
available.clear();
|
available.clear();
|
||||||
|
|
||||||
//set all joydevs anew (create new JoyPad's if necesary)
|
//set all joydevs anew (create new JoyPad's if necesary)
|
||||||
QDir DeviceDir(devdir);
|
QDir DeviceDir(devdir);
|
||||||
QStringList devices = DeviceDir.entryList(QStringList("js*"), QDir::System );
|
QStringList devices = DeviceDir.entryList("js*", QDir::System );
|
||||||
QRegExp devicename(".*\\js(\\d+)");
|
QRegExp devicename(".*\\js(\\d+)");
|
||||||
int joydev;
|
int joydev;
|
||||||
int index;
|
int index;
|
||||||
//for every joystick device in the directory listing...
|
//for every joystick device in the directory listing...
|
||||||
//(note, with devfs, only available devices are listed)
|
//(note, with devfs, only available devices are listed)
|
||||||
for (QStringList::Iterator it = devices.begin(); it != devices.end(); ++it) {
|
for (QStringList::Iterator it = devices.begin(); it != devices.end(); ++it) {
|
||||||
//try opening the device.
|
//try opening the device.
|
||||||
joydev = open( (devdir + "/" + (*it)).toStdString().c_str(), O_RDONLY | O_NONBLOCK);
|
joydev = open( devdir + "/" + (*it), O_RDONLY | O_NONBLOCK);
|
||||||
//if it worked, then we have a live joystick! Make sure it's properly
|
//if it worked, then we have a live joystick! Make sure it's properly
|
||||||
//setup.
|
//setup.
|
||||||
if (joydev > 0) {
|
if (joydev > 0) {
|
||||||
|
devicename.match(*it);
|
||||||
|
index = QString(devicename.cap(1)).toInt();
|
||||||
|
JoyPad* joypad;
|
||||||
|
//if we've never seen this device before, make a new one!
|
||||||
|
if (joypads[index] == 0) {
|
||||||
|
joypad = new JoyPad( index, joydev );
|
||||||
|
joypads.insert(index,joypad);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
joypad = joypads[index];
|
||||||
|
joypad->resetToDev(joydev);
|
||||||
|
}
|
||||||
|
//make this joystick device available.
|
||||||
|
available.insert(index,joypad);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
devicename.indexIn(*it);
|
//when it's all done, rebuild the popup menu so it displays the correct
|
||||||
index = QString(devicename.cap(1)).toInt();
|
//information.
|
||||||
JoyPad* joypad;
|
lm->fillPopup();
|
||||||
//if we've never seen this device before, make a new one!
|
|
||||||
if (joypads[index] == 0) {
|
|
||||||
struct pollfd read_struct;
|
|
||||||
read_struct.fd = joydev;
|
|
||||||
read_struct.events = POLLIN;
|
|
||||||
char buf[10];
|
|
||||||
while(poll(&read_struct, 1, 2)!=0) {
|
|
||||||
printf("reading junk data\n");
|
|
||||||
read(joydev, buf, 10);
|
|
||||||
}
|
|
||||||
joypad = new JoyPad( index, joydev );
|
|
||||||
joypads.insert(index,joypad);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
joypad = joypads[index];
|
|
||||||
joypad->resetToDev(joydev);
|
|
||||||
}
|
|
||||||
//make this joystick device available.
|
|
||||||
available.insert(index,joypad);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("done rebuilding joystick devices\n");
|
|
||||||
//when it's all done, rebuild the popup menu so it displays the correct
|
|
||||||
//information.
|
|
||||||
lm->fillPopup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -97,20 +101,19 @@ void buildJoyDevices() {
|
|||||||
// ~/.qjoypad/layout, where the last used layout is put.
|
// ~/.qjoypad/layout, where the last used layout is put.
|
||||||
void catchSIGIO( int sig )
|
void catchSIGIO( int sig )
|
||||||
{
|
{
|
||||||
lm->load();
|
lm->load();
|
||||||
//remember to catch this signal again next time.
|
//remember to catch this signal again next time.
|
||||||
signal( sig, catchSIGIO );
|
signal( sig, catchSIGIO );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//signal handler for SIGUSR1
|
//signal handler for SIGUSR1
|
||||||
//SIGUSR1 means that we should update the available joystick device list.
|
//SIGUSR1 means that we should update the available joystick device list.
|
||||||
void catchSIGUSR1( int sig ) {
|
void catchSIGUSR1( int sig ){
|
||||||
//buildJoyDevices();
|
buildJoyDevices();
|
||||||
lm->updateJoyDevs();
|
//remember to catch this signal again next time.
|
||||||
//remember to catch this signal again next time.
|
signal( sig, catchSIGUSR1 );
|
||||||
signal( sig, catchSIGUSR1 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -125,151 +128,151 @@ void catchSIGUSR2( int sig ) {
|
|||||||
|
|
||||||
int main( int argc, char **argv )
|
int main( int argc, char **argv )
|
||||||
{
|
{
|
||||||
//create a new event loop. This will be captured by the QApplication
|
//create a new event loop. This will be captured by the QApplication
|
||||||
//when it gets created
|
//when it gets created
|
||||||
|
JoyLoop loop;
|
||||||
QApplication a( argc, argv );
|
QApplication a( argc, argv );
|
||||||
|
|
||||||
|
|
||||||
//where to look for settings. If it does not exist, it will be created
|
//where to look for settings. If it does not exist, it will be created
|
||||||
QDir dir(settingsDir);
|
QDir dir(settingsDir);
|
||||||
|
|
||||||
//if there is no new directory and we can't make it, complain
|
//if there is no new directory and we can't make it, complain
|
||||||
if (!dir.exists() && !dir.mkdir(settingsDir)) {
|
if (!dir.exists() && !dir.mkdir(settingsDir)) {
|
||||||
printf("Couldn't create the QJoyPad save directory (%s)!", settingsDir.toStdString().c_str());
|
printf("Couldn't create the QJoyPad save directory (" + settingsDir + ")!");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//start out with no special layout.
|
//start out with no special layout.
|
||||||
QString layout = "";
|
QString layout = "";
|
||||||
//by default, we use a tray icon
|
//by default, we use a tray icon
|
||||||
bool useTrayIcon = true;
|
bool useTrayIcon = true;
|
||||||
//this execution wasn't made to update the joystick device list.
|
//this execution wasn't made to update the joystick device list.
|
||||||
bool update = false;
|
bool update = false;
|
||||||
|
|
||||||
|
|
||||||
//parse command-line options
|
//parse command-line options
|
||||||
for (int i = 1; i < a.argc(); i++) {
|
for (int i = 1; i < a.argc(); i++) {
|
||||||
//if a device directory was specified,
|
//if a device directory was specified,
|
||||||
if (QRegExp("-{1,2}device").exactMatch(a.argv()[i])) {
|
if (QRegExp("-{1,2}device").exactMatch(a.argv()[i])) {
|
||||||
++i;
|
++i;
|
||||||
if (i < a.argc()) {
|
if (i < a.argc()) {
|
||||||
if (QFile::exists(a.argv()[i])) {
|
if (QFile::exists(a.argv()[i])) {
|
||||||
devdir = a.argv()[i];
|
devdir = a.argv()[i];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
error("Command Line Argument Problems", "No such directory: " + QString(a.argv()[i]));
|
error("Command Line Argument Problems", "No such directory: " + QString(a.argv()[i]));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//if no-tray mode was requested,
|
//if no-tray mode was requested,
|
||||||
else if (QRegExp("-{1,2}notray").exactMatch(a.argv()[i])) {
|
else if (QRegExp("-{1,2}notray").exactMatch(a.argv()[i])) {
|
||||||
useTrayIcon = false;
|
useTrayIcon = false;
|
||||||
}
|
}
|
||||||
//if this execution is just meant to update the joystick devices,
|
//if this execution is just meant to update the joystick devices,
|
||||||
else if (QRegExp("-{1,2}update").exactMatch(a.argv()[i])) {
|
else if (QRegExp("-{1,2}update").exactMatch(a.argv()[i])) {
|
||||||
update = true;
|
update = true;
|
||||||
}
|
}
|
||||||
//if help was requested,
|
//if help was requested,
|
||||||
else if (QRegExp("-{1,2}h(elp)?").exactMatch(a.argv()[i])) {
|
else if (QRegExp("-{1,2}h(elp)?").exactMatch(a.argv()[i])) {
|
||||||
printf(NAME"\nUsage: qjoypad [--device \"/device/path\"] [--notray] [\"layout name\"]\n\nOptions:\n --device path Look for joystick devices in \"path\". This should\n be something like \"/dev/input\" if your game\n devices are in /dev/input/js0, /dev/input/js1, etc.\n --notray Do not use a system tray icon. This is useful for\n window managers that don't support this feature.\n --update Force a running instance of QJoyPad to update its\n list of devices and layouts.\n \"layout name\" Load the given layout in an already running\n instance of QJoyPad, or start QJoyPad using the\n given layout.\n");
|
printf(NAME"\nUsage: qjoypad [--device \"/device/path\"] [--notray] [\"layout name\"]\n\nOptions:\n --device path Look for joystick devices in \"path\". This should\n be something like \"/dev/input\" if your game\n devices are in /dev/input/js0, /dev/input/js1, etc.\n --notray Do not use a system tray icon. This is useful for\n window managers that don't support this feature.\n --update Force a running instance of QJoyPad to update its\n list of devices and layouts.\n \"layout name\" Load the given layout in an already running\n instance of QJoyPad, or start QJoyPad using the\n given layout.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
//in all other cases, an argument is assumed to be a layout name.
|
//in all other cases, an argument is assumed to be a layout name.
|
||||||
//note: only the last layout name given will be used.
|
//note: only the last layout name given will be used.
|
||||||
else layout = a.argv()[i];
|
else layout = a.argv()[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
//if the user specified a layout to use,
|
//if the user specified a layout to use,
|
||||||
if (layout != "")
|
if (layout != "")
|
||||||
{
|
{
|
||||||
//then we try to store that layout in the last-used layout spot, to be
|
//then we try to store that layout in the last-used layout spot, to be
|
||||||
//loaded by default.
|
//loaded by default.
|
||||||
QFile file( settingsDir + "layout");
|
QFile file( settingsDir + "layout");
|
||||||
if (file.open(QIODevice::WriteOnly))
|
if (file.open(IO_WriteOnly))
|
||||||
{
|
{
|
||||||
QTextStream stream( &file );
|
QTextStream stream( &file );
|
||||||
stream << layout;
|
stream << layout;
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//create a pid lock file.
|
//create a pid lock file.
|
||||||
QFile pidFile( "/tmp/qjoypad.pid" );
|
QFile pidFile( "/tmp/qjoypad.pid" );
|
||||||
//if that file already exists, then qjoypad is already running!
|
//if that file already exists, then qjoypad is already running!
|
||||||
if (pidFile.exists())
|
if (pidFile.exists())
|
||||||
{
|
{
|
||||||
int pid;
|
int pid;
|
||||||
if (pidFile.open( QIODevice::ReadOnly ));
|
if (pidFile.open( IO_ReadOnly ));
|
||||||
{
|
{
|
||||||
//try to get that pid...
|
//try to get that pid...
|
||||||
QTextStream( &pidFile ) >> pid;
|
QTextStream( &pidFile ) >> pid;
|
||||||
pidFile.close();
|
pidFile.close();
|
||||||
//if we can signal the pid (ie, if the process is active)
|
//if we can signal the pid (ie, if the process is active)
|
||||||
if (kill(pid,0) == 0)
|
if (kill(pid,0) == 0)
|
||||||
{
|
{
|
||||||
//then prevent two instances from running at once.
|
//then prevent two instances from running at once.
|
||||||
//however, if we are setting the layout or updating the device
|
//however, if we are setting the layout or updating the device
|
||||||
//list, this is not an error and we shouldn't make one!
|
//list, this is not an error and we shouldn't make one!
|
||||||
if (layout == "" && update == false) error("Instance Error","There is already a running instance of QJoyPad; please close\nthe old instance before starting a new one.");
|
if (layout == "" && update == false) error("Instance Error","There is already a running instance of QJoyPad; please close\nthe old instance before starting a new one.");
|
||||||
else {
|
else {
|
||||||
//if one of these is the case, send the approrpriate signal!
|
//if one of these is the case, send the approrpriate signal!
|
||||||
if (update == true)
|
if (update == true)
|
||||||
kill(pid,SIGUSR1);
|
kill(pid,SIGUSR1);
|
||||||
if (layout != "")
|
if (layout != "")
|
||||||
kill(pid,SIGIO);
|
kill(pid,SIGIO);
|
||||||
}
|
}
|
||||||
//and quit. We don't need two instances.
|
//and quit. We don't need two instances.
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//now we can try to create and write our pid to the lock file.
|
//now we can try to create and write our pid to the lock file.
|
||||||
if (pidFile.open( QIODevice::WriteOnly ))
|
if (pidFile.open( IO_WriteOnly ))
|
||||||
{
|
{
|
||||||
QTextStream( &pidFile ) << getpid();
|
QTextStream( &pidFile ) << getpid();
|
||||||
pidFile.close();
|
pidFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//prepare the signal handlers
|
//prepare the signal handlers
|
||||||
signal( SIGIO, catchSIGIO );
|
signal( SIGIO, catchSIGIO );
|
||||||
signal( SIGUSR1, catchSIGUSR1 );
|
signal( SIGUSR1, catchSIGUSR1 );
|
||||||
// signal( SIGUSR2, catchSIGUSR2 );
|
// signal( SIGUSR2, catchSIGUSR2 );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//capture the current display for event.h
|
//capture the current display for event.h
|
||||||
display = QX11Info::display();
|
display = QPaintDevice::x11AppDisplay();
|
||||||
|
|
||||||
//create a new LayoutManager with a tray icon / floating icon, depending
|
//create a new LayoutManager with a tray icon / floating icon, depending
|
||||||
//on the user's request
|
//on the user's request
|
||||||
lm = new LayoutManager(useTrayIcon);
|
lm = new LayoutManager(useTrayIcon);
|
||||||
|
|
||||||
//build the joystick device list for the first time,
|
//build the joystick device list for the first time,
|
||||||
//buildJoyDevices();
|
buildJoyDevices();
|
||||||
lm->updateJoyDevs();
|
|
||||||
|
|
||||||
//load the last used layout (Or the one given as a command-line argument)
|
//load the last used layout (Or the one given as a command-line argument)
|
||||||
lm->load();
|
lm->load();
|
||||||
|
|
||||||
//and run the program!
|
//and run the program!
|
||||||
int result = a.exec();
|
int result = a.exec();
|
||||||
|
|
||||||
//when everything is done, save the current layout for next time...
|
//when everything is done, save the current layout for next time...
|
||||||
lm->saveDefault();
|
lm->saveDefault();
|
||||||
|
|
||||||
//remove the lock file...
|
//remove the lock file...
|
||||||
pidFile.remove();
|
pidFile.remove();
|
||||||
|
|
||||||
//and terminate!
|
//and terminate!
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
BIN
src/qjoypad
BIN
src/qjoypad
Binary file not shown.
@ -27,8 +27,8 @@ doc.extra = cp ../README.txt ../LICENSE.txt $${doc.path}
|
|||||||
##### Setup Compile #####
|
##### Setup Compile #####
|
||||||
|
|
||||||
DEFINES += DEVDIR='"$$DEVDIR"'
|
DEFINES += DEVDIR='"$$DEVDIR"'
|
||||||
DEFINES += ICON24='\"$${icons.path}/icon24.png\"'
|
DEFINES += ICON24='"$${icons.path}/icon24.png"'
|
||||||
DEFINES += ICON64='\"$${icons.path}/icon64.png\"'
|
DEFINES += ICON64='"$${icons.path}/icon64.png"'
|
||||||
|
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
DEPENDPATH += trayicon
|
DEPENDPATH += trayicon
|
||||||
@ -42,6 +42,7 @@ HEADERS += axis.h \
|
|||||||
button.h \
|
button.h \
|
||||||
button_edit.h \
|
button_edit.h \
|
||||||
buttonw.h \
|
buttonw.h \
|
||||||
|
component.h \
|
||||||
constant.h \
|
constant.h \
|
||||||
device.h \
|
device.h \
|
||||||
error.h \
|
error.h \
|
||||||
@ -53,9 +54,10 @@ HEADERS += axis.h \
|
|||||||
joyslider.h \
|
joyslider.h \
|
||||||
keycode.h \
|
keycode.h \
|
||||||
layout.h \
|
layout.h \
|
||||||
getkey.h \
|
|
||||||
layout_edit.h \
|
layout_edit.h \
|
||||||
|
loop.h \
|
||||||
quickset.h \
|
quickset.h \
|
||||||
|
timer.h \
|
||||||
trayicon/trayicon.h
|
trayicon/trayicon.h
|
||||||
SOURCES += axis.cpp \
|
SOURCES += axis.cpp \
|
||||||
axis_edit.cpp \
|
axis_edit.cpp \
|
||||||
@ -72,9 +74,9 @@ SOURCES += axis.cpp \
|
|||||||
keycode.cpp \
|
keycode.cpp \
|
||||||
layout.cpp \
|
layout.cpp \
|
||||||
layout_edit.cpp \
|
layout_edit.cpp \
|
||||||
|
loop.cpp \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
quickset.cpp \
|
quickset.cpp \
|
||||||
getkey.cpp \
|
|
||||||
trayicon/trayicon.cpp \
|
trayicon/trayicon.cpp \
|
||||||
trayicon/trayicon_x11.cpp
|
trayicon/trayicon_x11.cpp
|
||||||
|
|
||||||
|
@ -1,57 +1,54 @@
|
|||||||
#include "quickset.h"
|
#include "quickset.h"
|
||||||
#include "getkey.h"
|
|
||||||
|
|
||||||
//build the dialog
|
//build the dialog
|
||||||
QuickSet::QuickSet( JoyPad* jp)
|
QuickSet::QuickSet( JoyPad* jp)
|
||||||
: QDialog() {
|
: QDialog(){
|
||||||
setting = false;
|
setting = false;
|
||||||
joypad = jp;
|
joypad = jp;
|
||||||
setWindowTitle("Set " + jp->getName());
|
setCaption("Quick set " + joypad->getName());
|
||||||
QVBoxLayout* LMain = new QVBoxLayout(this);
|
QVBoxLayout* LMain = new QVBoxLayout(this,5,5);
|
||||||
LMain->setMargin(5);
|
LMain->setAutoAdd(true);
|
||||||
LMain->setSpacing(5);
|
|
||||||
//LMain->setAutoAdd(true);
|
|
||||||
|
|
||||||
new QLabel("Press any button or axis and\nyou will be prompted for a key.",this);
|
new QLabel("Press any button or axis and\nyou will be prompted for a key.",this);
|
||||||
QPushButton* button = new QPushButton("Done",this);
|
QPushButton* button = new QPushButton("Done",this);
|
||||||
connect( button, SIGNAL(clicked()), this, SLOT(accept()));
|
connect( button, SIGNAL(clicked()), this, SLOT(accept()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void QuickSet::jsevent( js_event msg ) {
|
void QuickSet::jsevent( js_event msg ) {
|
||||||
//ignore any joystick events if we're waiting for a keypress
|
//ignore any joystick events if we're waiting for a keypress
|
||||||
if (setting) return;
|
if (setting) return;
|
||||||
|
|
||||||
//if a button was pressed on the joystick
|
//if a button was pressed on the joystick
|
||||||
if (msg.type == JS_EVENT_BUTTON) {
|
if (msg.type == JS_EVENT_BUTTON) {
|
||||||
//capture that button.
|
//capture that button.
|
||||||
Button* button = joypad->Buttons[msg.number];
|
Button* button = joypad->Buttons[msg.number];
|
||||||
|
|
||||||
//go into setting mode and request a key/mousebutton
|
//go into setting mode and request a key/mousebutton
|
||||||
setting = true;
|
setting = true;
|
||||||
int code = GetKey(button->getName(), true).exec();
|
int code = GetKey(button->getName(), true).exec();
|
||||||
setting = false;
|
setting = false;
|
||||||
|
|
||||||
//if a mouse button was used,
|
//if a mouse button was used,
|
||||||
if (code > MOUSE_OFFSET)
|
if (code > MOUSE_OFFSET)
|
||||||
//then tell it to the Button a mouse button
|
//then tell it to the Button a mouse button
|
||||||
button->setKey(true, code - MOUSE_OFFSET);
|
button->setKey(true, code - MOUSE_OFFSET);
|
||||||
else
|
else
|
||||||
//otherwise, tell it to use a keycode.
|
//otherwise, tell it to use a keycode.
|
||||||
button->setKey(false, code);
|
button->setKey(false, code);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//require a signal strength of at least 5000 to consider an axis moved.
|
//require a signal strength of at least 5000 to consider an axis moved.
|
||||||
if (abs(msg.value) < 5000) return;
|
if (abs(msg.value) < 5000) return;
|
||||||
|
|
||||||
//capture the axis that moved
|
//capture the axis that moved
|
||||||
Axis* axis = joypad->Axes[msg.number];
|
Axis* axis = joypad->Axes[msg.number];
|
||||||
|
|
||||||
//grab a keycode for that axis and that direction
|
//grab a keycode for that axis and that direction
|
||||||
setting = true;
|
setting = true;
|
||||||
int code = GetKey(axis->getName() + ", " + QString((msg.value > 0)?"positive":"negative"), false).exec();
|
int code = GetKey(axis->getName() + ", " + QString((msg.value > 0)?"positive":"negative"), false).exec();
|
||||||
setting = false;
|
setting = false;
|
||||||
|
|
||||||
//assign the key to the axis.
|
//assign the key to the axis.
|
||||||
axis->setKey((msg.value > 0),code);
|
axis->setKey((msg.value > 0),code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,12 @@
|
|||||||
#define QUICKSET_H
|
#define QUICKSET_H
|
||||||
|
|
||||||
//for building the dialog
|
//for building the dialog
|
||||||
#include <QLayout>
|
#include <qlayout.h>
|
||||||
#include <QLabel>
|
#include <qlabel.h>
|
||||||
#include <QPushButton>
|
#include <qpushbutton.h>
|
||||||
|
|
||||||
#include <linux/joystick.h>
|
|
||||||
|
|
||||||
//to request new keycodes
|
//to request new keycodes
|
||||||
//#include "keycode.h"
|
#include "keycode.h"
|
||||||
//to actually set the joypad
|
//to actually set the joypad
|
||||||
#include "joypad.h"
|
#include "joypad.h"
|
||||||
|
|
||||||
|
11
src/timer.h
Normal file
11
src/timer.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#ifndef JTIMER_H
|
||||||
|
#define JTIMER_H
|
||||||
|
|
||||||
|
#include "component.h"
|
||||||
|
|
||||||
|
//the purpose of this file is to make a list of Components that need timer
|
||||||
|
//notification available to JoyLoop, Axis, and Buttons
|
||||||
|
extern void takeTimer( Component* ); //taken from main.cpp
|
||||||
|
extern void tossTimer( Component* ); //taken from main.cpp
|
||||||
|
|
||||||
|
#endif
|
@ -19,6 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "trayicon.h"
|
#include "trayicon.h"
|
||||||
|
#include "qpopupmenu.h"
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class TrayIcon qtrayicon.h
|
\class TrayIcon qtrayicon.h
|
||||||
@ -32,9 +33,9 @@
|
|||||||
\sa show
|
\sa show
|
||||||
*/
|
*/
|
||||||
TrayIcon::TrayIcon( QObject *parent, const char *name )
|
TrayIcon::TrayIcon( QObject *parent, const char *name )
|
||||||
: QObject(parent/*, name*/), pop(0), d(0)
|
: QObject(parent, name), pop(0), d(0)
|
||||||
{
|
{
|
||||||
v_isWMDock = FALSE;
|
v_isWMDock = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -44,10 +45,10 @@ TrayIcon::TrayIcon( QObject *parent, const char *name )
|
|||||||
|
|
||||||
\sa show
|
\sa show
|
||||||
*/
|
*/
|
||||||
TrayIcon::TrayIcon( const QPixmap &icon, const QString &tooltip, QMenu *popup, QObject *parent, const char *name )
|
TrayIcon::TrayIcon( const QPixmap &icon, const QString &tooltip, QPopupMenu *popup, QObject *parent, const char *name )
|
||||||
: QObject(parent/*, name*/), pop(popup), pm(icon), tip(tooltip), d(0)
|
: QObject(parent, name), pop(popup), pm(icon), tip(tooltip), d(0)
|
||||||
{
|
{
|
||||||
v_isWMDock = FALSE;
|
v_isWMDock = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -62,7 +63,7 @@ TrayIcon::~TrayIcon()
|
|||||||
Sets the context menu to \a popup. The context menu will pop up when the
|
Sets the context menu to \a popup. The context menu will pop up when the
|
||||||
user clicks the system tray entry with the right mouse button.
|
user clicks the system tray entry with the right mouse button.
|
||||||
*/
|
*/
|
||||||
void TrayIcon::setPopup( QMenu* popup )
|
void TrayIcon::setPopup( QPopupMenu* popup )
|
||||||
{
|
{
|
||||||
pop = popup;
|
pop = popup;
|
||||||
}
|
}
|
||||||
@ -72,7 +73,7 @@ void TrayIcon::setPopup( QMenu* popup )
|
|||||||
|
|
||||||
\sa setPopup
|
\sa setPopup
|
||||||
*/
|
*/
|
||||||
QMenu* TrayIcon::popup() const
|
QPopupMenu* TrayIcon::popup() const
|
||||||
{
|
{
|
||||||
return pop;
|
return pop;
|
||||||
}
|
}
|
||||||
@ -138,22 +139,22 @@ bool TrayIcon::event( QEvent *e )
|
|||||||
{
|
{
|
||||||
switch ( e->type() ) {
|
switch ( e->type() ) {
|
||||||
case QEvent::MouseMove:
|
case QEvent::MouseMove:
|
||||||
mouseMoveEvent( (QMouseEvent*)e );
|
mouseMoveEvent( (QMouseEvent*)e );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QEvent::MouseButtonPress:
|
case QEvent::MouseButtonPress:
|
||||||
mousePressEvent( (QMouseEvent*)e );
|
mousePressEvent( (QMouseEvent*)e );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QEvent::MouseButtonRelease:
|
case QEvent::MouseButtonRelease:
|
||||||
mouseReleaseEvent( (QMouseEvent*)e );
|
mouseReleaseEvent( (QMouseEvent*)e );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QEvent::MouseButtonDblClick:
|
case QEvent::MouseButtonDblClick:
|
||||||
mouseDoubleClickEvent( (QMouseEvent*)e );
|
mouseDoubleClickEvent( (QMouseEvent*)e );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return QObject::event( e );
|
return QObject::event( e );
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -182,22 +183,22 @@ void TrayIcon::mousePressEvent( QMouseEvent *e )
|
|||||||
#ifndef Q_WS_WIN
|
#ifndef Q_WS_WIN
|
||||||
// This is for X11, menus appear on mouse press
|
// This is for X11, menus appear on mouse press
|
||||||
// I'm not sure whether Mac should be here or below.. Somebody check?
|
// I'm not sure whether Mac should be here or below.. Somebody check?
|
||||||
switch ( e->button() ) {
|
switch ( e->button() ) {
|
||||||
case Qt::RightButton:
|
case RightButton:
|
||||||
if ( pop ) {
|
if ( pop ) {
|
||||||
pop->popup( e->globalPos() );
|
pop->popup( e->globalPos() );
|
||||||
e->accept();
|
e->accept();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Qt::LeftButton:
|
case LeftButton:
|
||||||
case Qt::MidButton:
|
case MidButton:
|
||||||
emit clicked( e->globalPos(), e->button() );
|
emit clicked( e->globalPos(), e->button() );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
e->ignore();
|
e->ignore();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -214,26 +215,26 @@ void TrayIcon::mouseReleaseEvent( QMouseEvent *e )
|
|||||||
{
|
{
|
||||||
#ifdef Q_WS_WIN
|
#ifdef Q_WS_WIN
|
||||||
// This is for Windows, where menus appear on mouse release
|
// This is for Windows, where menus appear on mouse release
|
||||||
switch ( e->button() ) {
|
switch ( e->button() ) {
|
||||||
case Qt::RightButton:
|
case RightButton:
|
||||||
if ( pop ) {
|
if ( pop ) {
|
||||||
// Necessary to make keyboard focus
|
// Necessary to make keyboard focus
|
||||||
// and menu closing work on Windows.
|
// and menu closing work on Windows.
|
||||||
pop->setActiveWindow();
|
pop->setActiveWindow();
|
||||||
pop->popup( e->globalPos() );
|
pop->popup( e->globalPos() );
|
||||||
pop->setActiveWindow();
|
pop->setActiveWindow();
|
||||||
e->accept();
|
e->accept();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Qt::LeftButton:
|
case LeftButton:
|
||||||
case Qt::MidButton:
|
case MidButton:
|
||||||
emit clicked( e->globalPos(), e->button() );
|
emit clicked( e->globalPos(), e->button() );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
e->ignore();
|
e->ignore();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -248,9 +249,9 @@ void TrayIcon::mouseReleaseEvent( QMouseEvent *e )
|
|||||||
*/
|
*/
|
||||||
void TrayIcon::mouseDoubleClickEvent( QMouseEvent *e )
|
void TrayIcon::mouseDoubleClickEvent( QMouseEvent *e )
|
||||||
{
|
{
|
||||||
if ( e->button() == Qt::LeftButton )
|
if ( e->button() == LeftButton )
|
||||||
emit doubleClicked( e->globalPos() );
|
emit doubleClicked( e->globalPos() );
|
||||||
e->accept();
|
e->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -271,5 +272,5 @@ void TrayIcon::mouseDoubleClickEvent( QMouseEvent *e )
|
|||||||
|
|
||||||
void TrayIcon::gotCloseEvent()
|
void TrayIcon::gotCloseEvent()
|
||||||
{
|
{
|
||||||
closed();
|
closed();
|
||||||
}
|
}
|
||||||
|
@ -23,12 +23,8 @@
|
|||||||
|
|
||||||
#include <qobject.h>
|
#include <qobject.h>
|
||||||
#include <qimage.h>
|
#include <qimage.h>
|
||||||
#include <QPixmap>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QMenu>
|
|
||||||
#include <QMouseEvent>
|
|
||||||
|
|
||||||
|
|
||||||
|
class QPopupMenu;
|
||||||
|
|
||||||
class TrayIcon : public QObject
|
class TrayIcon : public QObject
|
||||||
{
|
{
|
||||||
@ -39,7 +35,7 @@ class TrayIcon : public QObject
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
TrayIcon( QObject *parent = 0, const char *name = 0 );
|
TrayIcon( QObject *parent = 0, const char *name = 0 );
|
||||||
TrayIcon( const QPixmap &, const QString &, QMenu *popup = 0, QObject *parent = 0, const char *name = 0 );
|
TrayIcon( const QPixmap &, const QString &, QPopupMenu *popup = 0, QObject *parent = 0, const char *name = 0 );
|
||||||
~TrayIcon();
|
~TrayIcon();
|
||||||
|
|
||||||
// use WindowMaker dock mode. ignored on non-X11 platforms
|
// use WindowMaker dock mode. ignored on non-X11 platforms
|
||||||
@ -47,8 +43,8 @@ public:
|
|||||||
bool isWMDock() { return v_isWMDock; }
|
bool isWMDock() { return v_isWMDock; }
|
||||||
|
|
||||||
// Set a popup menu to handle RMB
|
// Set a popup menu to handle RMB
|
||||||
void setPopup( QMenu * );
|
void setPopup( QPopupMenu * );
|
||||||
QMenu* popup() const;
|
QPopupMenu* popup() const;
|
||||||
|
|
||||||
QPixmap icon() const;
|
QPixmap icon() const;
|
||||||
QString toolTip() const;
|
QString toolTip() const;
|
||||||
@ -75,7 +71,7 @@ protected:
|
|||||||
virtual void mouseDoubleClickEvent( QMouseEvent *e );
|
virtual void mouseDoubleClickEvent( QMouseEvent *e );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMenu *pop;
|
QPopupMenu *pop;
|
||||||
QPixmap pm;
|
QPixmap pm;
|
||||||
QString tip;
|
QString tip;
|
||||||
bool v_isWMDock;
|
bool v_isWMDock;
|
||||||
|
@ -21,15 +21,18 @@
|
|||||||
|
|
||||||
#include "trayicon.h"
|
#include "trayicon.h"
|
||||||
|
|
||||||
#include <QX11Info>
|
#include<qapplication.h>
|
||||||
#include <QApplication>
|
#include<qimage.h>
|
||||||
#include <QPainter>
|
#include<qpixmap.h>
|
||||||
|
#include<qtooltip.h>
|
||||||
|
#include<qpainter.h>
|
||||||
|
|
||||||
#include<X11/Xlib.h>
|
#include<X11/Xlib.h>
|
||||||
#include<X11/Xutil.h>
|
#include<X11/Xutil.h>
|
||||||
#include<X11/Xatom.h>
|
#include<X11/Xatom.h>
|
||||||
|
|
||||||
//#if QT_VERSION < 0x030200
|
//#if QT_VERSION < 0x030200
|
||||||
//extern Time;// qt_x_time;
|
extern Time qt_x_time;
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@ -41,47 +44,47 @@ static XErrorHandler old_handler = 0;
|
|||||||
static int dock_xerror = 0;
|
static int dock_xerror = 0;
|
||||||
extern "C" int dock_xerrhandler(Display* dpy, XErrorEvent* err)
|
extern "C" int dock_xerrhandler(Display* dpy, XErrorEvent* err)
|
||||||
{
|
{
|
||||||
dock_xerror = err->error_code;
|
dock_xerror = err->error_code;
|
||||||
return old_handler(dpy, err);
|
return old_handler(dpy, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void trap_errors()
|
static void trap_errors()
|
||||||
{
|
{
|
||||||
dock_xerror = 0;
|
dock_xerror = 0;
|
||||||
old_handler = XSetErrorHandler(dock_xerrhandler);
|
old_handler = XSetErrorHandler(dock_xerrhandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool untrap_errors()
|
static bool untrap_errors()
|
||||||
{
|
{
|
||||||
XSetErrorHandler(old_handler);
|
XSetErrorHandler(old_handler);
|
||||||
return (dock_xerror == 0);
|
return (dock_xerror == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool send_message(
|
static bool send_message(
|
||||||
Display* dpy, /* display */
|
Display* dpy, /* display */
|
||||||
Window w, /* sender (tray icon window) */
|
Window w, /* sender (tray icon window) */
|
||||||
long message, /* message opcode */
|
long message, /* message opcode */
|
||||||
long data1, /* message data 1 */
|
long data1, /* message data 1 */
|
||||||
long data2, /* message data 2 */
|
long data2, /* message data 2 */
|
||||||
long data3 /* message data 3 */
|
long data3 /* message data 3 */
|
||||||
) {
|
) {
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
|
|
||||||
memset(&ev, 0, sizeof(ev));
|
memset(&ev, 0, sizeof(ev));
|
||||||
ev.xclient.type = ClientMessage;
|
ev.xclient.type = ClientMessage;
|
||||||
ev.xclient.window = w;
|
ev.xclient.window = w;
|
||||||
ev.xclient.message_type = XInternAtom (dpy, "_NET_SYSTEM_TRAY_OPCODE", False );
|
ev.xclient.message_type = XInternAtom (dpy, "_NET_SYSTEM_TRAY_OPCODE", False );
|
||||||
ev.xclient.format = 32;
|
ev.xclient.format = 32;
|
||||||
ev.xclient.data.l[0] = CurrentTime;
|
ev.xclient.data.l[0] = CurrentTime;
|
||||||
ev.xclient.data.l[1] = message;
|
ev.xclient.data.l[1] = message;
|
||||||
ev.xclient.data.l[2] = data1;
|
ev.xclient.data.l[2] = data1;
|
||||||
ev.xclient.data.l[3] = data2;
|
ev.xclient.data.l[3] = data2;
|
||||||
ev.xclient.data.l[4] = data3;
|
ev.xclient.data.l[4] = data3;
|
||||||
|
|
||||||
trap_errors();
|
trap_errors();
|
||||||
XSendEvent(dpy, w, False, NoEventMask, &ev);
|
XSendEvent(dpy, w, False, NoEventMask, &ev);
|
||||||
XSync(dpy, False);
|
XSync(dpy, False);
|
||||||
return untrap_errors();
|
return untrap_errors();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SYSTEM_TRAY_REQUEST_DOCK 0
|
#define SYSTEM_TRAY_REQUEST_DOCK 0
|
||||||
@ -95,125 +98,123 @@ static bool send_message(
|
|||||||
class TrayIcon::TrayIconPrivate : public QWidget
|
class TrayIcon::TrayIconPrivate : public QWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TrayIconPrivate(TrayIcon *object, int size);
|
TrayIconPrivate(TrayIcon *object, int size);
|
||||||
~TrayIconPrivate() { }
|
~TrayIconPrivate() { }
|
||||||
|
|
||||||
virtual void initWM(WId icon);
|
virtual void initWM(WId icon);
|
||||||
|
|
||||||
virtual void setPixmap(const QPixmap &pm);
|
virtual void setPixmap(const QPixmap &pm);
|
||||||
|
|
||||||
virtual void paintEvent(QPaintEvent *);
|
virtual void paintEvent(QPaintEvent *);
|
||||||
virtual void enterEvent(QEvent *);
|
virtual void enterEvent(QEvent *);
|
||||||
virtual void mouseMoveEvent(QMouseEvent *e);
|
virtual void mouseMoveEvent(QMouseEvent *e);
|
||||||
virtual void mousePressEvent(QMouseEvent *e);
|
virtual void mousePressEvent(QMouseEvent *e);
|
||||||
virtual void mouseReleaseEvent(QMouseEvent *e);
|
virtual void mouseReleaseEvent(QMouseEvent *e);
|
||||||
virtual void mouseDoubleClickEvent(QMouseEvent *e);
|
virtual void mouseDoubleClickEvent(QMouseEvent *e);
|
||||||
virtual void closeEvent(QCloseEvent *e);
|
virtual void closeEvent(QCloseEvent *e);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TrayIcon *iconObject;
|
TrayIcon *iconObject;
|
||||||
QPixmap pix;
|
QPixmap pix;
|
||||||
int size;
|
int size;
|
||||||
};
|
};
|
||||||
|
|
||||||
TrayIcon::TrayIconPrivate::TrayIconPrivate(TrayIcon *object, int _size)
|
TrayIcon::TrayIconPrivate::TrayIconPrivate(TrayIcon *object, int _size)
|
||||||
: QWidget(0/*, object->name(), Qt::WRepaintNoErase*/)
|
: QWidget(0, object->name(), WRepaintNoErase)
|
||||||
{
|
{
|
||||||
iconObject = object;
|
iconObject = object;
|
||||||
size = _size;
|
size = _size;
|
||||||
setAttribute(Qt::WA_NoBackground);
|
|
||||||
setFocusPolicy(Qt::NoFocus);
|
|
||||||
//setBackgroundMode(X11ParentRelative);
|
|
||||||
|
|
||||||
setMinimumSize(size, size);
|
setFocusPolicy(NoFocus);
|
||||||
setMaximumSize(size, size);
|
setBackgroundMode(X11ParentRelative);
|
||||||
|
|
||||||
|
setMinimumSize(size, size);
|
||||||
|
setMaximumSize(size, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This base stuff is required by both FreeDesktop specification and WindowMaker
|
// This base stuff is required by both FreeDesktop specification and WindowMaker
|
||||||
void TrayIcon::TrayIconPrivate::initWM(WId icon)
|
void TrayIcon::TrayIconPrivate::initWM(WId icon)
|
||||||
{
|
{
|
||||||
Display *dsp = x11Info().display();
|
Display *dsp = x11Display();
|
||||||
WId leader = winId();
|
WId leader = winId();
|
||||||
|
|
||||||
// set the class hint
|
// set the class hint
|
||||||
XClassHint classhint;
|
XClassHint classhint;
|
||||||
classhint.res_name = (char*)"psidock";
|
classhint.res_name = (char*)"psidock";
|
||||||
classhint.res_class = (char*)"Psi";
|
classhint.res_class = (char*)"Psi";
|
||||||
XSetClassHint(dsp, leader, &classhint);
|
XSetClassHint(dsp, leader, &classhint);
|
||||||
|
|
||||||
// set the Window Manager hints
|
// set the Window Manager hints
|
||||||
XWMHints *hints;
|
XWMHints *hints;
|
||||||
hints = XGetWMHints(dsp, leader); // init hints
|
hints = XGetWMHints(dsp, leader); // init hints
|
||||||
hints->flags = WindowGroupHint | IconWindowHint | StateHint; // set the window group hint
|
hints->flags = WindowGroupHint | IconWindowHint | StateHint; // set the window group hint
|
||||||
hints->window_group = leader; // set the window hint
|
hints->window_group = leader; // set the window hint
|
||||||
hints->initial_state = WithdrawnState; // initial state
|
hints->initial_state = WithdrawnState; // initial state
|
||||||
hints->icon_window = icon; // in WM, this should be winId() of separate widget
|
hints->icon_window = icon; // in WM, this should be winId() of separate widget
|
||||||
hints->icon_x = 0;
|
hints->icon_x = 0;
|
||||||
hints->icon_y = 0;
|
hints->icon_y = 0;
|
||||||
XSetWMHints(dsp, leader, hints); // set the window hints for WM to use.
|
XSetWMHints(dsp, leader, hints); // set the window hints for WM to use.
|
||||||
XFree( hints );
|
XFree( hints );
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayIcon::TrayIconPrivate::setPixmap(const QPixmap &pm)
|
void TrayIcon::TrayIconPrivate::setPixmap(const QPixmap &pm)
|
||||||
{
|
{
|
||||||
pix = pm;
|
pix = pm;
|
||||||
setWindowIcon(pix);
|
setIcon(pix);
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayIcon::TrayIconPrivate::paintEvent(QPaintEvent *)
|
void TrayIcon::TrayIconPrivate::paintEvent(QPaintEvent *)
|
||||||
{
|
{
|
||||||
QPainter p(this);
|
QPainter p(this);
|
||||||
p.drawPixmap((width() - pix.width())/2, (height() - pix.height())/2, pix);
|
p.drawPixmap((width() - pix.width())/2, (height() - pix.height())/2, pix);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayIcon::TrayIconPrivate::enterEvent(QEvent *e)
|
void TrayIcon::TrayIconPrivate::enterEvent(QEvent *e)
|
||||||
{
|
{
|
||||||
// Taken from KSystemTray..
|
// Taken from KSystemTray..
|
||||||
//#if QT_VERSION < 0x030200
|
//#if QT_VERSION < 0x030200
|
||||||
//if ( !qApp->focusWidget() ) {
|
//if ( !qApp->focusWidget() ) {
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
memset(&ev, 0, sizeof(ev));
|
memset(&ev, 0, sizeof(ev));
|
||||||
ev.xfocus.display = x11Info().display();//qt_xdisplay();
|
ev.xfocus.display = qt_xdisplay();
|
||||||
ev.xfocus.type = FocusIn;
|
ev.xfocus.type = FocusIn;
|
||||||
ev.xfocus.window = winId();
|
ev.xfocus.window = winId();
|
||||||
ev.xfocus.mode = NotifyNormal;
|
ev.xfocus.mode = NotifyNormal;
|
||||||
ev.xfocus.detail = NotifyAncestor;
|
ev.xfocus.detail = NotifyAncestor;
|
||||||
Time time = x11Info().appTime();//qt_x_time;
|
Time time = qt_x_time;
|
||||||
//qt_x_time = 1;
|
qt_x_time = 1;
|
||||||
x11Info().setAppTime(1);
|
qApp->x11ProcessEvent( &ev );
|
||||||
qApp->x11ProcessEvent( &ev );
|
qt_x_time = time;
|
||||||
//qt_x_time = time;
|
//}
|
||||||
x11Info().setAppTime(time);
|
|
||||||
//}
|
|
||||||
//#endif
|
//#endif
|
||||||
QWidget::enterEvent(e);
|
QWidget::enterEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayIcon::TrayIconPrivate::mouseMoveEvent(QMouseEvent *e)
|
void TrayIcon::TrayIconPrivate::mouseMoveEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
QApplication::sendEvent(iconObject, e);
|
QApplication::sendEvent(iconObject, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayIcon::TrayIconPrivate::mousePressEvent(QMouseEvent *e)
|
void TrayIcon::TrayIconPrivate::mousePressEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
QApplication::sendEvent(iconObject, e);
|
QApplication::sendEvent(iconObject, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayIcon::TrayIconPrivate::mouseReleaseEvent(QMouseEvent *e)
|
void TrayIcon::TrayIconPrivate::mouseReleaseEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
QApplication::sendEvent(iconObject, e);
|
QApplication::sendEvent(iconObject, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayIcon::TrayIconPrivate::mouseDoubleClickEvent(QMouseEvent *e)
|
void TrayIcon::TrayIconPrivate::mouseDoubleClickEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
QApplication::sendEvent(iconObject, e);
|
QApplication::sendEvent(iconObject, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayIcon::TrayIconPrivate::closeEvent(QCloseEvent *e)
|
void TrayIcon::TrayIconPrivate::closeEvent(QCloseEvent *e)
|
||||||
{
|
{
|
||||||
iconObject->gotCloseEvent();
|
iconObject->gotCloseEvent();
|
||||||
e->accept();
|
e->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@ -223,43 +224,43 @@ void TrayIcon::TrayIconPrivate::closeEvent(QCloseEvent *e)
|
|||||||
class TrayIconFreeDesktop : public TrayIcon::TrayIconPrivate
|
class TrayIconFreeDesktop : public TrayIcon::TrayIconPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TrayIconFreeDesktop(TrayIcon *object, const QPixmap &pm);
|
TrayIconFreeDesktop(TrayIcon *object, const QPixmap &pm);
|
||||||
};
|
};
|
||||||
|
|
||||||
TrayIconFreeDesktop::TrayIconFreeDesktop(TrayIcon *object, const QPixmap &pm)
|
TrayIconFreeDesktop::TrayIconFreeDesktop(TrayIcon *object, const QPixmap &pm)
|
||||||
: TrayIconPrivate(object, 22)
|
: TrayIconPrivate(object, 22)
|
||||||
{
|
{
|
||||||
initWM( winId() );
|
initWM( winId() );
|
||||||
|
|
||||||
// initialize NetWM
|
// initialize NetWM
|
||||||
Display *dsp = x11Info().display();//x11Display();
|
Display *dsp = x11Display();
|
||||||
|
|
||||||
// dock the widget (adapted from SIM-ICQ)
|
// dock the widget (adapted from SIM-ICQ)
|
||||||
Screen *screen = XDefaultScreenOfDisplay(dsp); // get the screen
|
Screen *screen = XDefaultScreenOfDisplay(dsp); // get the screen
|
||||||
int screen_id = XScreenNumberOfScreen(screen); // and it's number
|
int screen_id = XScreenNumberOfScreen(screen); // and it's number
|
||||||
|
|
||||||
char buf[32];
|
char buf[32];
|
||||||
snprintf(buf, sizeof(buf), "_NET_SYSTEM_TRAY_S%d", screen_id);
|
snprintf(buf, sizeof(buf), "_NET_SYSTEM_TRAY_S%d", screen_id);
|
||||||
Atom selection_atom = XInternAtom(dsp, buf, false);
|
Atom selection_atom = XInternAtom(dsp, buf, false);
|
||||||
XGrabServer(dsp);
|
XGrabServer(dsp);
|
||||||
Window manager_window = XGetSelectionOwner(dsp, selection_atom);
|
Window manager_window = XGetSelectionOwner(dsp, selection_atom);
|
||||||
if ( manager_window != None )
|
if ( manager_window != None )
|
||||||
XSelectInput(dsp, manager_window, StructureNotifyMask);
|
XSelectInput(dsp, manager_window, StructureNotifyMask);
|
||||||
XUngrabServer(dsp);
|
XUngrabServer(dsp);
|
||||||
XFlush(dsp);
|
XFlush(dsp);
|
||||||
|
|
||||||
if ( manager_window != None )
|
if ( manager_window != None )
|
||||||
send_message(dsp, manager_window, SYSTEM_TRAY_REQUEST_DOCK, winId(), 0, 0);
|
send_message(dsp, manager_window, SYSTEM_TRAY_REQUEST_DOCK, winId(), 0, 0);
|
||||||
|
|
||||||
// some KDE mumbo-jumbo... why is it there? anybody?
|
// some KDE mumbo-jumbo... why is it there? anybody?
|
||||||
Atom kwm_dockwindow_atom = XInternAtom(dsp, "KWM_DOCKWINDOW", false);
|
Atom kwm_dockwindow_atom = XInternAtom(dsp, "KWM_DOCKWINDOW", false);
|
||||||
Atom kde_net_system_tray_window_for_atom = XInternAtom(dsp, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
|
Atom kde_net_system_tray_window_for_atom = XInternAtom(dsp, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
|
||||||
|
|
||||||
long data = 0;
|
long data = 0;
|
||||||
XChangeProperty(dsp, winId(), kwm_dockwindow_atom, kwm_dockwindow_atom, 32, PropModeReplace, (uchar*)&data, 1);
|
XChangeProperty(dsp, winId(), kwm_dockwindow_atom, kwm_dockwindow_atom, 32, PropModeReplace, (uchar*)&data, 1);
|
||||||
XChangeProperty(dsp, winId(), kde_net_system_tray_window_for_atom, XA_WINDOW, 32, PropModeReplace, (uchar*)&data, 1);
|
XChangeProperty(dsp, winId(), kde_net_system_tray_window_for_atom, XA_WINDOW, 32, PropModeReplace, (uchar*)&data, 1);
|
||||||
|
|
||||||
setPixmap(pm);
|
setPixmap(pm);
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@ -269,58 +270,58 @@ TrayIconFreeDesktop::TrayIconFreeDesktop(TrayIcon *object, const QPixmap &pm)
|
|||||||
class TrayIconWharf : public TrayIcon::TrayIconPrivate
|
class TrayIconWharf : public TrayIcon::TrayIconPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TrayIconWharf(TrayIcon *object, const QPixmap &pm)
|
TrayIconWharf(TrayIcon *object, const QPixmap &pm)
|
||||||
: TrayIconPrivate(object, 64)
|
: TrayIconPrivate(object, 64)
|
||||||
{
|
{
|
||||||
setPixmap(pm);
|
setPixmap(pm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPixmap(const QPixmap &_pm)
|
void setPixmap(const QPixmap &_pm)
|
||||||
{
|
{
|
||||||
QPixmap pm;
|
QPixmap pm;
|
||||||
QImage i = _pm.toImage();
|
QImage i = _pm.convertToImage();
|
||||||
i = i.scaled(i.width() * 2, i.height() * 2);
|
i = i.scale(i.width() * 2, i.height() * 2);
|
||||||
pm = QPixmap::fromImage(i);
|
pm.convertFromImage(i);
|
||||||
|
|
||||||
TrayIconPrivate::setPixmap(pm);
|
TrayIconPrivate::setPixmap(pm);
|
||||||
|
|
||||||
// thanks to Robert Spier for this:
|
// thanks to Robert Spier for this:
|
||||||
// for some reason the repaint() isn't being honored, or isn't for
|
// for some reason the repaint() isn't being honored, or isn't for
|
||||||
// the icon. So force one on the widget behind the icon
|
// the icon. So force one on the widget behind the icon
|
||||||
//erase();
|
erase();
|
||||||
QPaintEvent pe( rect() );
|
QPaintEvent pe( rect() );
|
||||||
paintEvent(&pe);
|
paintEvent(&pe);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class TrayIconWindowMaker : public TrayIcon::TrayIconPrivate
|
class TrayIconWindowMaker : public TrayIcon::TrayIconPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TrayIconWindowMaker(TrayIcon *object, const QPixmap &pm);
|
TrayIconWindowMaker(TrayIcon *object, const QPixmap &pm);
|
||||||
~TrayIconWindowMaker();
|
~TrayIconWindowMaker();
|
||||||
|
|
||||||
void setPixmap(const QPixmap &pm);
|
void setPixmap(const QPixmap &pm);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TrayIconWharf *wharf;
|
TrayIconWharf *wharf;
|
||||||
};
|
};
|
||||||
|
|
||||||
TrayIconWindowMaker::TrayIconWindowMaker(TrayIcon *object, const QPixmap &pm)
|
TrayIconWindowMaker::TrayIconWindowMaker(TrayIcon *object, const QPixmap &pm)
|
||||||
: TrayIconPrivate(object, 32)
|
: TrayIconPrivate(object, 32)
|
||||||
{
|
{
|
||||||
wharf = new TrayIconWharf(object, pm);
|
wharf = new TrayIconWharf(object, pm);
|
||||||
|
|
||||||
initWM( wharf->winId() );
|
initWM( wharf->winId() );
|
||||||
}
|
}
|
||||||
|
|
||||||
TrayIconWindowMaker::~TrayIconWindowMaker()
|
TrayIconWindowMaker::~TrayIconWindowMaker()
|
||||||
{
|
{
|
||||||
delete wharf;
|
delete wharf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayIconWindowMaker::setPixmap(const QPixmap &pm)
|
void TrayIconWindowMaker::setPixmap(const QPixmap &pm)
|
||||||
{
|
{
|
||||||
wharf->setPixmap(pm);
|
wharf->setPixmap(pm);
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@ -329,46 +330,43 @@ void TrayIconWindowMaker::setPixmap(const QPixmap &pm)
|
|||||||
|
|
||||||
void TrayIcon::sysInstall()
|
void TrayIcon::sysInstall()
|
||||||
{
|
{
|
||||||
if ( d )
|
if ( d )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( v_isWMDock )
|
if ( v_isWMDock )
|
||||||
d = (TrayIconPrivate *)(new TrayIconWindowMaker(this, pm));
|
d = (TrayIconPrivate *)(new TrayIconWindowMaker(this, pm));
|
||||||
else
|
else
|
||||||
d = (TrayIconPrivate *)(new TrayIconFreeDesktop(this, pm));
|
d = (TrayIconPrivate *)(new TrayIconFreeDesktop(this, pm));
|
||||||
|
|
||||||
sysUpdateToolTip();
|
sysUpdateToolTip();
|
||||||
d->show();
|
d->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayIcon::sysRemove()
|
void TrayIcon::sysRemove()
|
||||||
{
|
{
|
||||||
if ( !d )
|
if ( !d )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
delete d;
|
delete d;
|
||||||
d = 0;
|
d = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayIcon::sysUpdateIcon()
|
void TrayIcon::sysUpdateIcon()
|
||||||
{
|
{
|
||||||
if ( !d )
|
if ( !d )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QPixmap pix = pm;
|
QPixmap pix = pm;
|
||||||
d->setPixmap(pix);
|
d->setPixmap(pix);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayIcon::sysUpdateToolTip()
|
void TrayIcon::sysUpdateToolTip()
|
||||||
{
|
{
|
||||||
if ( !d )
|
if ( !d )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( tip.isEmpty() ) {
|
if ( tip.isEmpty() )
|
||||||
//QToolTip::remove(d);
|
QToolTip::remove(d);
|
||||||
d->setToolTip(QString());
|
else
|
||||||
} else {
|
QToolTip::add(d, tip);
|
||||||
//QToolTip::add(d, tip);
|
|
||||||
d->setToolTip(tip);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user