summaryrefslogtreecommitdiffstats
path: root/minuitwrp
diff options
context:
space:
mode:
Diffstat (limited to 'minuitwrp')
-rw-r--r--minuitwrp/events.c80
-rw-r--r--minuitwrp/graphics.c10
-rw-r--r--minuitwrp/minui.h3
3 files changed, 84 insertions, 9 deletions
diff --git a/minuitwrp/events.c b/minuitwrp/events.c
index 73369a2cc..94942ba7b 100644
--- a/minuitwrp/events.c
+++ b/minuitwrp/events.c
@@ -20,8 +20,11 @@
#include <dirent.h>
#include <sys/poll.h>
#include <limits.h>
-
#include <linux/input.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
#include "../common.h"
@@ -95,6 +98,9 @@ struct ev {
static struct pollfd ev_fds[MAX_DEVICES];
static struct ev evs[MAX_DEVICES];
static unsigned ev_count = 0;
+static struct timeval lastInputStat;
+static unsigned long lastInputMTime;
+static int has_mouse = 0;
static inline int ABS(int x) {
return x<0?-x:x;
@@ -106,6 +112,8 @@ int vibrate(int timeout_ms)
int fd;
int ret;
+ if (timeout_ms > 10000) timeout_ms = 1000;
+
fd = open(VIBRATOR_TIMEOUT_FILE, O_WRONLY);
if (fd < 0)
return -1;
@@ -237,12 +245,41 @@ static int vk_init(struct ev *e)
return 0;
}
+#define BITS_PER_LONG (sizeof(long) * 8)
+#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
+#define OFF(x) ((x)%BITS_PER_LONG)
+#define LONG(x) ((x)/BITS_PER_LONG)
+#define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
+static void check_mouse(int fd)
+{
+ if(has_mouse)
+ return;
+
+ unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
+ memset(bit, 0, sizeof(bit));
+ ioctl(fd, EVIOCGBIT(0, EV_MAX), bit[0]);
+
+ if(!test_bit(EV_REL, bit[0]))
+ return;
+
+ ioctl(fd, EVIOCGBIT(EV_REL, KEY_MAX), bit[EV_REL]);
+ if(test_bit(REL_X, bit[EV_REL]) && test_bit(REL_Y, bit[EV_REL]))
+ has_mouse = 1;
+}
+
+int ev_has_mouse(void)
+{
+ return has_mouse;
+}
+
int ev_init(void)
{
DIR *dir;
struct dirent *de;
int fd;
+ has_mouse = 0;
+
dir = opendir("/dev/input");
if(dir != 0) {
while((de = readdir(dir))) {
@@ -258,23 +295,32 @@ int ev_init(void)
/* Load virtualkeys if there are any */
vk_init(&evs[ev_count]);
+ check_mouse(fd);
+
ev_count++;
if(ev_count == MAX_DEVICES) break;
}
+ closedir(dir);
}
+ struct stat st;
+ if(stat("/dev/input", &st) >= 0)
+ lastInputMTime = st.st_mtime;
+ gettimeofday(&lastInputStat, NULL);
+
return 0;
}
void ev_exit(void)
{
- while (ev_count-- > 0) {
- if (evs[ev_count].vk_count) {
- free(evs[ev_count].vks);
- evs[ev_count].vk_count = 0;
+ while (ev_count-- > 0) {
+ if (evs[ev_count].vk_count) {
+ free(evs[ev_count].vks);
+ evs[ev_count].vk_count = 0;
+ }
+ close(ev_fds[ev_count].fd);
}
- close(ev_fds[ev_count].fd);
- }
+ ev_count = 0;
}
static int vk_inside_display(__s32 value, struct input_absinfo *info, int screen_size)
@@ -627,9 +673,25 @@ int ev_get(struct input_event *ev, unsigned dont_wait)
{
int r;
unsigned n;
+ struct timeval curr;
do {
- r = poll(ev_fds, ev_count, dont_wait ? 0 : -1);
+ gettimeofday(&curr, NULL);
+ if(curr.tv_sec - lastInputStat.tv_sec >= 2)
+ {
+ struct stat st;
+ stat("/dev/input", &st);
+ if (st.st_mtime > lastInputMTime)
+ {
+ LOGI("Reloading input devices\n");
+ ev_exit();
+ ev_init();
+ lastInputMTime = st.st_mtime;
+ }
+ lastInputStat = curr;
+ }
+
+ r = poll(ev_fds, ev_count, 0);
if(r > 0) {
for(n = 0; n < ev_count; n++) {
@@ -642,6 +704,8 @@ int ev_get(struct input_event *ev, unsigned dont_wait)
}
}
}
+
+ usleep(1000);
} while(dont_wait == 0);
return -1;
diff --git a/minuitwrp/graphics.c b/minuitwrp/graphics.c
index 99f584183..ddff571fe 100644
--- a/minuitwrp/graphics.c
+++ b/minuitwrp/graphics.c
@@ -483,13 +483,21 @@ void gr_blit(gr_surface source, int sx, int sy, int w, int h, int dx, int dy) {
}
GGLContext *gl = gr_context;
- gl->bindTexture(gl, (GGLSurface*) source);
+ GGLSurface *surface = (GGLSurface*)source;
+
+ if(surface->format == GGL_PIXEL_FORMAT_RGBX_8888)
+ gl->disable(gl, GGL_BLEND);
+
+ gl->bindTexture(gl, surface);
gl->texEnvi(gl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE);
gl->texGeni(gl, GGL_S, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
gl->texGeni(gl, GGL_T, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
gl->enable(gl, GGL_TEXTURE_2D);
gl->texCoord2i(gl, sx - dx, sy - dy);
gl->recti(gl, dx, dy, dx + w, dy + h);
+
+ if(surface->format == GGL_PIXEL_FORMAT_RGBX_8888)
+ gl->enable(gl, GGL_BLEND);
}
unsigned int gr_get_width(gr_surface surface) {
diff --git a/minuitwrp/minui.h b/minuitwrp/minui.h
index 03e15bb81..bbdfdfb50 100644
--- a/minuitwrp/minui.h
+++ b/minuitwrp/minui.h
@@ -58,6 +58,7 @@ struct input_event;
int ev_init(void);
void ev_exit(void);
int ev_get(struct input_event *ev, unsigned dont_wait);
+int ev_has_mouse(void);
// Resources
@@ -70,4 +71,6 @@ int ev_wait(int timeout);
void ev_dispatch(void);
int ev_get_input(int fd, short revents, struct input_event *ev);
+int vibrate(int timeout_ms);
+
#endif