aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbhgv <bhgv.empire@gmail.com>2019-05-05 18:44:35 +0300
committerbhgv <bhgv.empire@gmail.com>2019-05-05 18:44:35 +0300
commitc76314f0f38f4ed028610a6db4452879a556b35f (patch)
tree63754fc80ae254aafc018da9bd21cd520df52129
parenta1ca1b6a61a5c9913cb82a903ef0962496c9fba4 (diff)
auto-select capacitive or resistive touchscreens. bigger toolbar, menu, keyboard and captions
-rw-r--r--appl/alib/titlebar.b3
-rw-r--r--appl/awm/atoolbar.b49
-rw-r--r--appl/awm/keyboard.b8
-rw-r--r--emu/Linux/win-fb.c192
-rw-r--r--mkconfig1
5 files changed, 216 insertions, 37 deletions
diff --git a/appl/alib/titlebar.b b/appl/alib/titlebar.b
index dc9c161..bed8d4d 100644
--- a/appl/alib/titlebar.b
+++ b/appl/alib/titlebar.b
@@ -44,8 +44,7 @@ init()
new(top: ref Tk->Toplevel, buts: int): chan of string
{
r := top.screenr;
- h_title = int (r.dy() / 30);
-
+ h_title = int (1.5 * real r.dy() / 30.0);
fnt_csz := int ( h_title * 2/3);
fnt_nm := FONT_TTF + "_" + string fnt_csz;
diff --git a/appl/awm/atoolbar.b b/appl/awm/atoolbar.b
index 0a0cda8..654b1a2 100644
--- a/appl/awm/atoolbar.b
+++ b/appl/awm/atoolbar.b
@@ -38,6 +38,8 @@ tb_fnt : ref Font;
tb_h := 0;
+is_hrz := (0 == 0);
+
# execute this if no menu items have been created
# by the init script.
defaultscript :=
@@ -243,13 +245,22 @@ iconify(id, label: string)
label = condenselabel(label);
padf := ".toolbar.sp"+id;
- tk->cmd(tbtop, "frame " + padf + " -width 2");
- cmd(tbtop, "pack " + padf + " -side left -fill y");
+ if (is_hrz) {
+ tk->cmd(tbtop, "frame " + padf + " -height 2");
+ cmd(tbtop, "pack " + padf + " -side top -fill x");
+ } else {
+ tk->cmd(tbtop, "frame " + padf + " -width 2");
+ cmd(tbtop, "pack " + padf + " -side left -fill y");
+ }
e := tk->cmd(tbtop, "button .toolbar." +id+" -command {send task "+id+"} -takefocus 0");
- cmd(tbtop, ".toolbar." +id+" configure -font " + tb_fnt.name + " -text '" + label);
- if(e[0] != '!')
- cmd(tbtop, "pack .toolbar."+id+" -side left -fill y");
+ cmd(tbtop, ".toolbar." +id+" configure -font " + tb_fnt.name + " -height " + string tb_h + " -text '" + label);
+ if (e[0] != '!') {
+ if (is_hrz)
+ cmd(tbtop, "pack .toolbar."+id+" -side top -fill x");
+ else
+ cmd(tbtop, "pack .toolbar."+id+" -side left -fill y");
+ }
cmd(tbtop, "update");
}
@@ -271,10 +282,18 @@ layout(top: ref Tk->Toplevel)
h := tb_h; #60; #32;
if(r.dy() < 480)
h = tk->rect(top, ".b", Tk->Border|Tk->Required).dy();
- cmd(top, ". configure -x " + string r.min.x +
+ if (is_hrz)
+ cmd(top, ". configure -x " + string r.min.x +
+ " -y " + string r.min.y + #(r.max.y - h) +
+ " -width " + string h +
+ " -height " + string r.dy()
+ );
+ else
+ cmd(top, ". configure -x " + string r.min.x +
" -y " + string r.min.y + #(r.max.y - h) +
" -width " + string r.dx() +
- " -height " + string h);
+ " -height " + string h
+ );
cmd(top, "update");
tkclient->onscreen(tbtop, "exact");
}
@@ -286,7 +305,9 @@ toolbar(ctxt: ref Draw->Context, startmenu: int,
screenr = tbtop.screenr;
- tb_h = screenr.dy() / 20;
+ tb_h = int (1.5 * real screenr.dy() / 20.0);
+
+ is_hrz = (screenr.dx() > screenr.dy());
fnt_csz := int ( tb_h / 2);
fnt_nm := FONT_TTF + "_" + string fnt_csz;
@@ -307,10 +328,16 @@ toolbar(ctxt: ref Draw->Context, startmenu: int,
cmd(tbtop, "menubutton .toolbar.start -menu .m -borderwidth 0 -bitmap :"
+ string int tb_h
+ ":vitabig.png");
- cmd(tbtop, "pack .toolbar.start -side left");
+ if (is_hrz)
+ cmd(tbtop, "pack .toolbar.start -side top");
+ else
+ cmd(tbtop, "pack .toolbar.start -side left");
}
- cmd(tbtop, "pack .toolbar -fill x");
+ if (is_hrz)
+ cmd(tbtop, "pack .toolbar -fill x");
+ else
+ cmd(tbtop, "pack .toolbar -fill y");
cmd(tbtop, "menu .m");
return tbtop;
}
@@ -412,7 +439,7 @@ builtin_menu(nil: ref Context, nil: Sh, argv: list of ref Listnode): string
primary := (hd tl argv).word;
argv = tl tl argv;
- h_mnu_itm := string int (screenr.dy() / 30);
+ h_mnu_itm := string int (tb_h); #screenr.dy() / 30);
tb_fnt_nm := tb_fnt.name;
diff --git a/appl/awm/keyboard.b b/appl/awm/keyboard.b
index 8e14042..aff2704 100644
--- a/appl/awm/keyboard.b
+++ b/appl/awm/keyboard.b
@@ -40,7 +40,7 @@ SPECFONT_TTF: con "/fonts/ttf/FantasqueSansMono-Regular.ttf";
# size in pixels
#KEYSIZE: con 16;
-KEYSIZE: con 13;
+KEYSIZE: con 16; #13;
KEYSPACE: con 2;
KEYBORDER: con 1;
KEYGAP: con KEYSPACE - (2 * KEYBORDER);
@@ -145,10 +145,10 @@ init(ctxt: ref Draw->Context, args: list of string)
# sys->print("scrn WxH = %dx%d bsz=%d - %d\n", r.dx(), r.dy(), r.dx()/15, KEYBORDER);
wkbd := r.dx();
if(wkbd > r.dy())
- wkbd = int wkbd/2;
+ wkbd = int (2*wkbd/3);
KEYGAP_ := int wkbd/100;
- KEYSIZE_ := int wkbd/15 - KEYGAP_;
+ KEYSIZE_ := int (wkbd/15) - KEYGAP_;
specials[ Backslash ].size = KEYSIZE_;
specials[ Esc ].size = KEYSIZE_;
@@ -172,7 +172,7 @@ init(ctxt: ref Draw->Context, args: list of string)
if(keys[0][i] != nil)
cmd(t, sys->sprint("button .b%d -takefocus 0 -font %s -width %d -height %d -bd %d -activebackground %s -text {%s} -command 'send keypress %d",
i, fnt_nm #FONT
- , KEYSIZE_, int (KEYSIZE_ * 3/2),
+ , KEYSIZE_, KEYSIZE_, #int (KEYSIZE_ * 3/2),
KEYBORDER, background, keys[0][i], keyvals[0][i]));
for(i = 0; i < len specials; i++) {
diff --git a/emu/Linux/win-fb.c b/emu/Linux/win-fb.c
index 08d9be5..a05af68 100644
--- a/emu/Linux/win-fb.c
+++ b/emu/Linux/win-fb.c
@@ -24,6 +24,7 @@
#include <linux/fb.h>
#include <sys/mman.h>
#include <stdio.h>
+#include <dirent.h>
#include <linux/input.h>
@@ -37,6 +38,7 @@
#define LOGW(...) //printf(__VA_ARGS__)
#define LOGE(...) //printf(__VA_ARGS__)
+#define DBG(...) printf(__VA_ARGS__)
static int displaydepth = 32;
@@ -85,7 +87,20 @@ static int putsnarf, assertsnarf;
extern int Xsize;
extern int Ysize;
-int fd_mou = -1;
+static int Xmou_max = 0;
+static int Ymou_max = 0;
+
+static int fd_mou = -1;
+static int is_mt = 0;
+
+
+static char *supported_mouse_devs[] = {
+ "Goodix Capacitive TouchScreen",
+ "TSC2003 Touchscreen",
+ "TSC2007 Touchscreen",
+ NULL
+};
+
/*
* The documentation for the XSHM extension implies that if the server
@@ -229,6 +244,143 @@ attach_fb()
}
+
+
+
+#define BITS_PER_LONG (sizeof(long) * 8)
+#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
+#define OFF(x) ((x)%BITS_PER_LONG)
+#define BIT(x) (1UL<<OFF(x))
+#define LONG(x) ((x)/BITS_PER_LONG)
+#define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
+
+static int is_event_device(const struct dirent *dir) {
+ return strncmp("event", dir->d_name, 5) == 0;
+}
+
+static int
+scan_mouse()
+{
+ struct dirent **namelist;
+ int i, j, ndev;
+ int fd = -1, fd_cap = -1, fd_res = -1;
+ char fname[64];
+ char *dname = malloc(256);
+
+ unsigned long bits[NBITS(KEY_MAX)];
+ struct input_absinfo abs;
+
+ int touch_res;
+ int touch_cap;
+
+ ndev = scandir("/dev/input", &namelist, is_event_device, versionsort);
+ if (ndev <= 0)
+ return -1;
+DBG("ndev=%d\n", ndev);
+
+ for(i = 0; i < ndev; i++){
+ int is_supported = 0;
+
+ snprintf(fname, sizeof(fname), "/dev/input/%s", namelist[i]->d_name);
+DBG("test file: %s\n", fname);
+
+ fd = open(fname, O_RDWR);
+ if (fd < 0)
+ continue;
+
+ ioctl(fd, EVIOCGNAME(256), dname);
+DBG("test dev: %s\n", dname);
+ for(j = 0; supported_mouse_devs[j] != NULL; j++){
+ if(!strcmp(dname, supported_mouse_devs[j])){
+ is_supported = 1;
+ break;
+ }
+ }
+
+ if(!is_supported){
+ close(fd);
+ continue;
+ }
+DBG("supported: %s\n", fname);
+
+ ioctl(fd, EVIOCGBIT(0, EV_MAX), bits);
+ if (!test_bit(EV_ABS, bits)){
+ close(fd);
+ continue;
+ }
+
+ ioctl(fd, EVIOCGBIT(EV_ABS, KEY_MAX), bits);
+ if(!(
+ test_bit(ABS_MT_POSITION_X, bits) &&
+ test_bit(ABS_MT_POSITION_Y, bits)
+ )
+ ){
+ if(fd_res >= 0)
+ close(fd_res);
+ fd_res = fd;
+DBG("RESISTIVE\n");
+ }else{
+ if(fd_cap >= 0)
+ close(fd_cap);
+ fd_cap = fd;
+DBG("CAPACITIVE\n");
+ }
+ }
+
+ if(fd_cap < 0){
+ ioctl(fd, EVIOCGABS (ABS_X), &abs);
+ Xmou_max = abs.maximum;
+#if 0
+ context->min.x = abs.minimum;
+ context->max.x = abs.maximum;
+#endif
+ ioctl (fd, EVIOCGABS (ABS_Y), &abs);
+ Ymou_max = abs.maximum;
+#if 0
+ context->max.y = abs.maximum;
+ context->have_multitouch = 0;
+ context->min.id = -1;
+ context->max.id = -1;
+#endif
+ is_mt = 0;
+ fd = fd_res;
+ }else{
+ if(fd_res >= 0)
+ close(fd_res);
+
+ ioctl (fd, EVIOCGABS (ABS_MT_POSITION_X), &abs);
+ Xmou_max = abs.maximum;
+ printf(">O X = (%d -- %d)\n", abs.minimum, abs.maximum);
+/*
+ abs.maximum = 800;
+ ioctl (fd, EVIOCSABS (ABS_MT_POSITION_X), &abs);
+ ioctl (fd, EVIOCGABS (ABS_MT_POSITION_X), &abs);
+ printf(">N X = (%d -- %d)\n", abs.minimum, abs.maximum);
+*/
+ // ----
+ ioctl (fd, EVIOCGABS (ABS_MT_POSITION_Y), &abs);
+ Ymou_max = abs.maximum;
+ printf(">O Y = (%d -- %d)\n", abs.minimum, abs.maximum);
+/*
+ abs.maximum = 480;
+ ioctl (fd, EVIOCSABS (ABS_MT_POSITION_Y), &abs);
+ ioctl (fd, EVIOCGABS (ABS_MT_POSITION_Y), &abs);
+ printf(">N Y = (%d -- %d)\n", abs.minimum, abs.maximum);
+*/
+ // ----
+ is_mt = 1;
+ fd = fd_cap;
+ }
+DBG("is_mt=%d\n", is_mt);
+
+ free(dname);
+
+ return fd;
+}
+
+
+
+
uchar*
attachscreen(Rectangle *r, ulong *chan, int *d, int *width, int *softscreen)
{
@@ -248,7 +400,7 @@ LOGE("attachscreen\n");
// prepare mouse
if(fd_mou == -1){
- fd_mou = open("/dev/input/event1", O_RDWR);
+ fd_mou = scan_mouse(); //open("/dev/input/event1", O_RDWR);
}
triedscreen = 1;
@@ -1083,7 +1235,7 @@ xkeyboard() ///*XEvent*/void *e)
}
-#if TOUCHSCREEN_CAPACITIVE
+
typedef struct {
int x;
@@ -1186,7 +1338,6 @@ static int capacitive_events(int fd, int* b, int* x, int* y)
return !is_changed;
}
-#else
/*
** calibration (perfect = 0 0 4096 4096)
@@ -1349,8 +1500,6 @@ static int tsc2003_events(int fd, int* b, int* x, int* y)
return 0;
}
-#endif
-
static void
xmouse() //XEvent *e)
@@ -1373,20 +1522,25 @@ xmouse() //XEvent *e)
// }
if(fd_mou >= 0){
-#if TOUCHSCREEN_CAPACITIVE
- if(!capacitive_events(fd_mou, &b, &x, &y)){
- //printf("capt x=%d, y=%d, b=%x\n", x, y, b);
- mousetrack(b, x, y, 0);
- }
-#else
- tsc2003_events(fd_mou, &b, &x, &y);
- if(b > 0 || (b == 0 && ob > 0)){
- ob = b;
- //printf("rest x=%d, y=%d, b=%x\n", x, y, b);
- mousetrack(b, x, y, 0);
- //printf("ob = %d, b=%d, xy=(%d, %d)\n", ob, b, x, y);
+//#if TOUCHSCREEN_CAPACITIVE
+ if(is_mt){
+ if(Xmou_max > 0 && Ymou_max && !capacitive_events(fd_mou, &b, &x, &y)){
+ x = (x * Xsize) / Xmou_max;
+ y = (y * Ysize) / Ymou_max;
+ //printf("capt x=%d, y=%d, b=%x\n", x, y, b);
+ mousetrack(b, x, y, 0);
+ }
+ }else{
+//#else
+ tsc2003_events(fd_mou, &b, &x, &y);
+ if(b > 0 || (b == 0 && ob > 0)){
+ ob = b;
+ //printf("rest x=%d, y=%d, b=%x\n", x, y, b);
+ mousetrack(b, x, y, 0);
+ //printf("ob = %d, b=%d, xy=(%d, %d)\n", ob, b, x, y);
+ }
}
-#endif
+//#endif
}
#if 0
dbl = 0;
diff --git a/mkconfig b/mkconfig
index 81be67f..e66a052 100644
--- a/mkconfig
+++ b/mkconfig
@@ -12,7 +12,6 @@ ROOT=$ROOT
TKSTYLE=std
WINDOW_BACKEND=fb # andr, clutter, x11a, fb
-TOUCHSCREEN_CAPACITIVE=1
#
# Except for building kernels, SYSTARG must always be the same as SYSHOST