mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-26 11:56:16 +02:00
Use an enum instead of hardcoded values for the user-injected codes
This commit is contained in:
parent
a0515ad356
commit
b0fa6db97d
@ -178,18 +178,29 @@ bool InputManager::getEvent(ButtonEvent *bevent, bool wait) {
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case SDL_USEREVENT:
|
case SDL_USEREVENT:
|
||||||
if (!event.user.code)
|
switch ((enum EventCode) event.user.code) {
|
||||||
|
case REMOVE_LINKS:
|
||||||
menu->removePackageLink((const char *) event.user.data1);
|
menu->removePackageLink((const char *) event.user.data1);
|
||||||
else if (event.user.code == 1)
|
break;
|
||||||
|
case OPEN_PACKAGE:
|
||||||
menu->openPackage((const char *) event.user.data1);
|
menu->openPackage((const char *) event.user.data1);
|
||||||
else if (event.user.code == 2)
|
break;
|
||||||
|
case OPEN_PACKAGES_FROM_DIR:
|
||||||
menu->openPackagesFromDir(
|
menu->openPackagesFromDir(
|
||||||
((string) (const char *) event.user.data1
|
((string) (const char *) event.user.data1
|
||||||
+ "/apps").c_str());
|
+ "/apps").c_str());
|
||||||
|
break;
|
||||||
|
case REPAINT_MENU:
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.user.data1)
|
||||||
free(event.user.data1);
|
free(event.user.data1);
|
||||||
bevent->state = PRESSED;
|
bevent->state = PRESSED;
|
||||||
bevent->button = REPAINT;
|
bevent->button = REPAINT;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,13 @@
|
|||||||
|
|
||||||
class Menu;
|
class Menu;
|
||||||
|
|
||||||
|
enum EventCode {
|
||||||
|
REMOVE_LINKS,
|
||||||
|
OPEN_PACKAGE,
|
||||||
|
OPEN_PACKAGES_FROM_DIR,
|
||||||
|
REPAINT_MENU,
|
||||||
|
};
|
||||||
|
|
||||||
class InputManager {
|
class InputManager {
|
||||||
public:
|
public:
|
||||||
enum Button {
|
enum Button {
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include "inputmanager.h"
|
||||||
#include "mediamonitor.h"
|
#include "mediamonitor.h"
|
||||||
|
|
||||||
MediaMonitor::MediaMonitor(std::string dir) :
|
MediaMonitor::MediaMonitor(std::string dir) :
|
||||||
@ -21,7 +22,7 @@ void MediaMonitor::inject_event(bool is_add, const char *path)
|
|||||||
{
|
{
|
||||||
SDL_UserEvent e = {
|
SDL_UserEvent e = {
|
||||||
.type = SDL_USEREVENT,
|
.type = SDL_USEREVENT,
|
||||||
.code = is_add ? 2 : 0,
|
.code = is_add ? OPEN_PACKAGES_FROM_DIR : REMOVE_LINKS,
|
||||||
.data1 = strdup(path),
|
.data1 = strdup(path),
|
||||||
.data2 = NULL,
|
.data2 = NULL,
|
||||||
};
|
};
|
||||||
|
@ -8,13 +8,14 @@
|
|||||||
#include <sys/inotify.h>
|
#include <sys/inotify.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "inputmanager.h"
|
||||||
#include "monitor.h"
|
#include "monitor.h"
|
||||||
|
|
||||||
void Monitor::inject_event(bool is_add, const char *path)
|
void Monitor::inject_event(bool is_add, const char *path)
|
||||||
{
|
{
|
||||||
SDL_UserEvent e = {
|
SDL_UserEvent e = {
|
||||||
.type = SDL_USEREVENT,
|
.type = SDL_USEREVENT,
|
||||||
.code = (int) is_add,
|
.code = is_add ? OPEN_PACKAGE : REMOVE_LINKS,
|
||||||
.data1 = strdup(path),
|
.data1 = strdup(path),
|
||||||
.data2 = NULL,
|
.data2 = NULL,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user