mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-22 18:23:08 +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;
|
||||
#endif
|
||||
case SDL_USEREVENT:
|
||||
if (!event.user.code)
|
||||
menu->removePackageLink((const char *) event.user.data1);
|
||||
else if (event.user.code == 1)
|
||||
menu->openPackage((const char *) event.user.data1);
|
||||
else if (event.user.code == 2)
|
||||
menu->openPackagesFromDir(
|
||||
((string) (const char *) event.user.data1
|
||||
+ "/apps").c_str());
|
||||
free(event.user.data1);
|
||||
switch ((enum EventCode) event.user.code) {
|
||||
case REMOVE_LINKS:
|
||||
menu->removePackageLink((const char *) event.user.data1);
|
||||
break;
|
||||
case OPEN_PACKAGE:
|
||||
menu->openPackage((const char *) event.user.data1);
|
||||
break;
|
||||
case OPEN_PACKAGES_FROM_DIR:
|
||||
menu->openPackagesFromDir(
|
||||
((string) (const char *) event.user.data1
|
||||
+ "/apps").c_str());
|
||||
break;
|
||||
case REPAINT_MENU:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (event.user.data1)
|
||||
free(event.user.data1);
|
||||
bevent->state = PRESSED;
|
||||
bevent->button = REPAINT;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -26,6 +26,13 @@
|
||||
|
||||
class Menu;
|
||||
|
||||
enum EventCode {
|
||||
REMOVE_LINKS,
|
||||
OPEN_PACKAGE,
|
||||
OPEN_PACKAGES_FROM_DIR,
|
||||
REPAINT_MENU,
|
||||
};
|
||||
|
||||
class InputManager {
|
||||
public:
|
||||
enum Button {
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "debug.h"
|
||||
#include "inputmanager.h"
|
||||
#include "mediamonitor.h"
|
||||
|
||||
MediaMonitor::MediaMonitor(std::string dir) :
|
||||
@ -21,7 +22,7 @@ void MediaMonitor::inject_event(bool is_add, const char *path)
|
||||
{
|
||||
SDL_UserEvent e = {
|
||||
.type = SDL_USEREVENT,
|
||||
.code = is_add ? 2 : 0,
|
||||
.code = is_add ? OPEN_PACKAGES_FROM_DIR : REMOVE_LINKS,
|
||||
.data1 = strdup(path),
|
||||
.data2 = NULL,
|
||||
};
|
||||
|
@ -8,13 +8,14 @@
|
||||
#include <sys/inotify.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "inputmanager.h"
|
||||
#include "monitor.h"
|
||||
|
||||
void Monitor::inject_event(bool is_add, const char *path)
|
||||
{
|
||||
SDL_UserEvent e = {
|
||||
.type = SDL_USEREVENT,
|
||||
.code = (int) is_add,
|
||||
.code = is_add ? OPEN_PACKAGE : REMOVE_LINKS,
|
||||
.data1 = strdup(path),
|
||||
.data2 = NULL,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user