=================================================================== ChangeSet@xxxx, 2004-08-10 01:12:33-05:00, dtor_core@xxxxxxxxxxxxx Separate console and selection handling, separate library and server console implementation so server can be changed freely without fear of breaking clients API. Makefile.in | 8 +- client.c | 1 console.c | 171 ++++++++++++++-------------------------------------- gpm.c | 1 gpn.c | 1 headers/console.h | 16 ---- headers/selection.h | 37 +++++++++++ lib/tools.c | 81 ++++++++++++++++++++++++ selection.c | 156 +++++++++++++++++++++++++++++++++++++++++++++++ startup.c | 4 - tools.c | 81 ------------------------ 11 files changed, 335 insertions(+), 222 deletions(-) =================================================================== diff -Nru a/src/Makefile.in b/src/Makefile.in --- a/src/Makefile.in 2004-08-10 01:18:02 -05:00 +++ b/src/Makefile.in 2004-08-10 01:18:02 -05:00 @@ -15,13 +15,13 @@ MICESRC = mice.c twiddler.c synaptics.c @EVDEV_SRCS@ GSRC = main.c gpm.c gpn.c special.c startup.c server_tools.c console.c \ - client.c optparser.c $(MICESRC) + selection.c client.c optparser.c $(MICESRC) -GOBJ = $(GSRC:.c=.o) report.o tools.o +GOBJ = $(GSRC:.c=.o) report.o -LSRC = lib/liblow.c lib/libhigh.c lib/libxtra.c lib/report-lib.c +LSRC = lib/liblow.c lib/libhigh.c lib/libxtra.c lib/report-lib.c lib/tools.c -LOBJ = $(LSRC:.c=.o) tools.o @CURSES_OBJS@ +LOBJ = $(LSRC:.c=.o) @CURSES_OBJS@ PICS = $(LOBJ:.o=.lo) diff -Nru a/src/client.c b/src/client.c --- a/src/client.c 2004-08-10 01:18:02 -05:00 +++ b/src/client.c 2004-08-10 01:18:02 -05:00 @@ -39,6 +39,7 @@ #include "headers/gpmInt.h" #include "headers/message.h" #include "headers/console.h" +#include "headers/selection.h" #include "headers/client.h" /* who the f*** runs gpm without glibc? doesn't have dietlibc __socklent_t? */ diff -Nru a/src/console.c b/src/console.c --- a/src/console.c 2004-08-10 01:18:02 -05:00 +++ b/src/console.c 2004-08-10 01:18:02 -05:00 @@ -46,10 +46,33 @@ # endif #endif -struct sel_options sel_opts = { 0, 0, DEF_PTRDRAG }; struct gpm_console console = { 0, DEF_LUT, 0, 0 }; -static time_t last_selection_time; +/*-------------------------------------------------------------------*/ +static int count_digits(int num) +{ + int digits = 1; + + while ((num /= 10)) + digits++; + + return digits; +} + +/*-------------------------------------------------------------------*/ +char *compose_vc_name(int vc) +{ + char *tty; + + tty = malloc(strlen(console.device) + count_digits(vc) + sizeof(char)); + if (tty) { + /* console is /dev/vc/0 or /dev/tty0 and we trimming the ending 0 */ + strncpy(tty, console.device, strlen(console.device) - 1); + sprintf(&tty[strlen(console.device) - 1], "%d", vc); + } + + return tty; +} /*-------------------------------------------------------------------*/ int open_console(int mode) @@ -129,23 +152,15 @@ char *tty; int rc; - tty = malloc(strlen(console.device) + Gpm_cnt_digits(vc) + sizeof(char)); - if (!tty) - gpm_report(GPM_PR_OOPS,GPM_MESS_NO_MEM); - - strncpy(tty, console.device, strlen(console.device) - 1); - sprintf(&tty[strlen(console.device) - 1], "%d", vc); + if ((tty = compose_vc_name(vc)) == NULL) + gpm_report(GPM_PR_OOPS, GPM_MESS_NO_MEM); - rc = stat(tty, &statbuf); + if ((rc = stat(tty, &statbuf)) == -1) + gpm_report(GPM_PR_ERR, GPM_MESS_STAT_FAILS, tty); free(tty); - if (rc == -1) { - gpm_report(GPM_PR_ERR, GPM_MESS_STAT_FAILS, tty); - return 0; - } - - return uid == statbuf.st_uid; + return rc != -1 && uid == statbuf.st_uid; } /*-------------------------------------------------------------------*/ @@ -218,113 +233,25 @@ } /*-------------------------------------------------------------------*/ -static void selection_copy(int x1, int y1, int x2, int y2, int mode) -{ - /* - * The approach in "selection" causes a bus error when run under SunOS 4.1 - * due to alignment problems... - */ - unsigned char buf[6 * sizeof(short)]; - unsigned short *arg = (unsigned short *)buf + 1; - int fd; - - buf[sizeof(short) - 1] = 2; /* set selection */ +/* Returns the name of the console (/dev/tty0 or /dev/vc/0) */ +/* Also fills console.device */ +char *get_console_name() +{ + struct stat buf; + + /* first try the devfs device, because in the next time this will be + * the preferred one. If that fails, take the old console */ + + /* Check for open new console */ + if (stat(GPM_DEVFS_CONSOLE, &buf) == 0) + console.device = GPM_DEVFS_CONSOLE; + + /* Failed, try OLD console */ + else if (stat(GPM_OLD_CONSOLE, &buf) == 0) + console.device = GPM_OLD_CONSOLE; + else + gpm_report(GPM_PR_OOPS, "Can't determine console device"); - arg[0] = (unsigned short)x1; - arg[1] = (unsigned short)y1; - arg[2] = (unsigned short)x2; - arg[3] = (unsigned short)y2; - arg[4] = (unsigned short)mode; - - if ((fd = open_console(O_WRONLY)) < 0) - gpm_report(GPM_PR_OOPS, GPM_MESS_OPEN_CON); - - gpm_report(GPM_PR_DEBUG, "ctl %i, mode %i", (int)*buf, arg[4]); - if (ioctl(fd, TIOCLINUX, buf + sizeof(short) - 1) < 0) - gpm_report(GPM_PR_OOPS,GPM_MESS_IOCTL_TIOCLINUX); - close(fd); - - if (mode < 3) { - sel_opts.aged = 0; - last_selection_time = time(0); - } -} - -/*-------------------------------------------------------------------*/ -static void selection_paste(void) -{ - char c = 3; - int fd; - - if (!sel_opts.aged && - sel_opts.age_limit != 0 && - last_selection_time + sel_opts.age_limit < time(0)) { - sel_opts.aged = 1; - } - - if (sel_opts.aged) - gpm_report(GPM_PR_DEBUG, GPM_MESS_SKIP_PASTE); - else { - fd = open_console(O_WRONLY); - if (ioctl(fd, TIOCLINUX, &c) < 0) - gpm_report(GPM_PR_OOPS, GPM_MESS_IOCTL_TIOCLINUX); - close(fd); - } -} - -/*-------------------------------------------------------------------*/ -void do_selection(Gpm_Event *event, int three_button_mode) -{ - static int x1 = 1, y1 = 1; - int x2, y2; - - x2 = event->x; y2 = event->y; - switch (GPM_BARE_EVENTS(event->type)) { - case GPM_MOVE: - if (x2 < 1) x2++; else if (x2 > console.max_x) x2--; - if (y2 < 1) y2++; else if (y2 > console.max_y) y2--; - selection_copy(x2, y2, x2, y2, 3); /* just highlight the pointer */ - break; - - case GPM_DRAG: - if (event->buttons == GPM_B_LEFT) { - switch(event->margin) { /* fix margins */ - case GPM_TOP: x2 = 1; y2++; break; - case GPM_BOT: x2 = console.max_x; y2--; break; - case GPM_RGT: x2--; break; - case GPM_LFT: y2 <= y1 ? x2++ : (x2 = console.max_x, y2--); break; - default: break; - } - selection_copy(x1, y1, x2, y2, event->clicks); - if (event->clicks >= sel_opts.ptrdrag && !event->margin) /* pointer */ - selection_copy(x2, y2, x2, y2, 3); - } /* if */ - break; - - case GPM_DOWN: - switch (event->buttons) { - case GPM_B_LEFT: - x1 = x2; y1 = y2; - selection_copy(x1, y1, x2, y2, event->clicks); /* start selection */ - break; - - case GPM_B_MIDDLE: - selection_paste(); - break; - - case GPM_B_RIGHT: - if (three_button_mode == 1) - selection_copy(x1, y1, x2, y2, event->clicks); - else - selection_paste(); - break; - } - } /* switch above */ -} - -/*-------------------------------------------------------------------*/ -void selection_disable_paste(void) -{ - sel_opts.aged = 1; + return console.device; } diff -Nru a/src/gpm.c b/src/gpm.c --- a/src/gpm.c 2004-08-10 01:18:01 -05:00 +++ b/src/gpm.c 2004-08-10 01:18:02 -05:00 @@ -37,6 +37,7 @@ #include "headers/gpmInt.h" #include "headers/message.h" #include "headers/console.h" +#include "headers/selection.h" #include "headers/client.h" #ifndef max diff -Nru a/src/gpn.c b/src/gpn.c --- a/src/gpn.c 2004-08-10 01:18:02 -05:00 +++ b/src/gpn.c 2004-08-10 01:18:02 -05:00 @@ -34,6 +34,7 @@ #include "headers/gpmInt.h" #include "headers/gpm.h" #include "headers/console.h" +#include "headers/selection.h" /* usage: display for usage informations */ int usage(char *whofailed) diff -Nru a/src/headers/console.h b/src/headers/console.h --- a/src/headers/console.h 2004-08-10 01:18:02 -05:00 +++ b/src/headers/console.h 2004-08-10 01:18:02 -05:00 @@ -27,26 +27,16 @@ int max_x, max_y; }; -struct sel_options { - int aged; - int age_limit; - int ptrdrag; -}; - -struct Gpm_Event; - -extern struct sel_options sel_opts; /* only one exists */ -extern struct gpm_console console; /* same */ +extern struct gpm_console console; int open_console(int mode); +char *get_console_name(); +char *compose_vc_name(int vc); int is_text_console(void); void wait_text_console(void); void refresh_console_size(void); int is_console_owner(int vc, uid_t uid); int get_console_state(unsigned char *shift_state); void console_load_lut(void); - -void do_selection(struct Gpm_Event *event, int three_button_mode); -void selection_disable_paste(void); #endif /* __GPM_CONSOLE_H_ */ diff -Nru a/src/headers/selection.h b/src/headers/selection.h --- /dev/null Wed Dec 31 16:00:00 196900 +++ b/src/headers/selection.h 2004-08-10 01:18:02 -05:00 @@ -0,0 +1,37 @@ +/* + * selection.h - GPM selection/copy/paste handling + * + * Copyright (C) 2003 Dmitry Torokhov <dtor@xxxxxxx> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + ********/ + +#ifndef __GPM_SELECTION_H_ +#define __GPM_SELECTION_H_ + +struct sel_options { + int aged; + int age_limit; + int ptrdrag; +}; + +struct Gpm_Event; + +extern struct sel_options sel_opts; /* only one exists */ + +void do_selection(struct Gpm_Event *event, int three_button_mode); +void selection_disable_paste(void); + +#endif /* __GPM_SELECTION_H_ */ diff -Nru a/src/lib/tools.c b/src/lib/tools.c --- /dev/null Wed Dec 31 16:00:00 196900 +++ b/src/lib/tools.c 2004-08-10 01:18:01 -05:00 @@ -0,0 +1,81 @@ +/* + * tools.c - tools which are needed by client and server + * + * Copyright (c) 2001 Nico Schottelius <nico@xxxxxxxxxxxxxxx> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + ********/ + +#include <stdio.h> /* NULL */ +#include <string.h> +#include <stdlib.h> +#include <sys/types.h> /* these three are */ +#include <sys/stat.h> /* needed for */ +#include <unistd.h> /* stat() */ + +#include "headers/gpmInt.h" /* only used for some defines */ + +/***************************************************************************** + * check, whether devfs is used or not. + * See /usr/src/linux/Documentation/filesystems/devfs/ for details. + * Returns: the name of the console (/dev/tty0 or /dev/vc/0) + *****************************************************************************/ +char *Gpm_get_console(void) +{ + struct stat buf; + + /* first try the devfs device, because in the next time this will be + * the preferred one. If that fails, take the old console */ + + /* Check for open new console */ + if (stat(GPM_DEVFS_CONSOLE, &buf) == 0) + return strdup(GPM_DEVFS_CONSOLE); + + /* Failed, try OLD console */ + else if (stat(GPM_OLD_CONSOLE, &buf) == 0) + return strdup(GPM_OLD_CONSOLE); + + return NULL; +} + +/* what's the english name for potenz ? */ +int Gpm_x_high_y(int base, int pot_y) +{ + int val = 1; + + if (pot_y == 0) val = 1; + else if (pot_y < 0) val = 0; /* ugly hack ;) */ + else while(pot_y > 0) { + val = val * base; + pot_y--; + } + return val; +} + +/* return characters needed to display int */ +int Gpm_cnt_digits(int number) +{ + /* 0-9 = 1 10^0 <-> (10^1)-1 + * 10 - 99 = 2 10^1 <-> (10^2)-1 + * 100 - 999 = 3 10^2 <-> (10^3)-1 + * 1000 - 9999 = 4 ... */ + + int digits = 1; + + while ((number /= 10)) + digits++; + + return digits; +} diff -Nru a/src/selection.c b/src/selection.c --- /dev/null Wed Dec 31 16:00:00 196900 +++ b/src/selection.c 2004-08-10 01:18:02 -05:00 @@ -0,0 +1,156 @@ +/* + * selection.c - GPM selection/copy/paste handling + * + * Copyright (C) 1993 Andreq Haylett <ajh@xxxxxxxxxxxxx> + * Copyright (C) 1994-1999 Alessandro Rubini <rubini@xxxxxxxx> + * Copyright (C) 1998 Ian Zimmerman <itz@xxxxxxxxx> + * Copyright (c) 2001,2002 Nico Schottelius <nico-gpm@xxxxxxxxxxxxxxx> + * Copyright (c) 2003 Dmitry Torokhov <dtor@xxxxxxx> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + ********/ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> /* strerror(); ?!? */ +#include <errno.h> +#include <unistd.h> /* select(); */ +#include <time.h> /* time() */ +#include <sys/fcntl.h> /* O_RDONLY */ +#include <sys/stat.h> /* mkdir() */ +#include <asm/types.h> /* __u32 */ + +#include <linux/vt.h> /* VT_GETSTATE */ +#include <sys/kd.h> /* KDGETMODE */ +#include <termios.h> /* winsize */ + +#include "headers/gpmInt.h" +#include "headers/message.h" +#include "headers/console.h" +#include "headers/selection.h" + +struct sel_options sel_opts = { 0, 0, DEF_PTRDRAG }; +static time_t last_selection_time; + +/*-------------------------------------------------------------------*/ +static void selection_copy(int x1, int y1, int x2, int y2, int mode) +{ + /* + * The approach in "selection" causes a bus error when run under SunOS 4.1 + * due to alignment problems... + */ + unsigned char buf[6 * sizeof(short)]; + unsigned short *arg = (unsigned short *)buf + 1; + int fd; + + buf[sizeof(short) - 1] = 2; /* set selection */ + + arg[0] = (unsigned short)x1; + arg[1] = (unsigned short)y1; + arg[2] = (unsigned short)x2; + arg[3] = (unsigned short)y2; + arg[4] = (unsigned short)mode; + + if ((fd = open_console(O_WRONLY)) < 0) + gpm_report(GPM_PR_OOPS, GPM_MESS_OPEN_CON); + + gpm_report(GPM_PR_DEBUG, "ctl %i, mode %i", (int)*buf, arg[4]); + if (ioctl(fd, TIOCLINUX, buf + sizeof(short) - 1) < 0) + gpm_report(GPM_PR_OOPS, GPM_MESS_IOCTL_TIOCLINUX); + close(fd); + + if (mode < 3) { + sel_opts.aged = 0; + last_selection_time = time(0); + } +} + +/*-------------------------------------------------------------------*/ +static void selection_paste(void) +{ + char c = 3; + int fd; + + if (!sel_opts.aged && + sel_opts.age_limit != 0 && + last_selection_time + sel_opts.age_limit < time(0)) { + sel_opts.aged = 1; + } + + if (sel_opts.aged) { + gpm_report(GPM_PR_DEBUG, GPM_MESS_SKIP_PASTE); + } else { + fd = open_console(O_WRONLY); + if (ioctl(fd, TIOCLINUX, &c) < 0) + gpm_report(GPM_PR_OOPS, GPM_MESS_IOCTL_TIOCLINUX); + close(fd); + } +} + +/*-------------------------------------------------------------------*/ +void do_selection(Gpm_Event *event, int three_button_mode) +{ + static int x1 = 1, y1 = 1; + int x2, y2; + + x2 = event->x; y2 = event->y; + switch (GPM_BARE_EVENTS(event->type)) { + case GPM_MOVE: + if (x2 < 1) x2++; else if (x2 > console.max_x) x2--; + if (y2 < 1) y2++; else if (y2 > console.max_y) y2--; + selection_copy(x2, y2, x2, y2, 3); /* just highlight the pointer */ + break; + + case GPM_DRAG: + if (event->buttons == GPM_B_LEFT) { + switch (event->margin) { /* fix margins */ + case GPM_TOP: x2 = 1; y2++; break; + case GPM_BOT: x2 = console.max_x; y2--; break; + case GPM_RGT: x2--; break; + case GPM_LFT: y2 <= y1 ? x2++ : (x2 = console.max_x, y2--); break; + default: break; + } + selection_copy(x1, y1, x2, y2, event->clicks); + if (event->clicks >= sel_opts.ptrdrag && !event->margin) /* pointer */ + selection_copy(x2, y2, x2, y2, 3); + } + break; + + case GPM_DOWN: + switch (event->buttons) { + case GPM_B_LEFT: + x1 = x2; y1 = y2; + selection_copy(x1, y1, x2, y2, event->clicks); /* start selection */ + break; + + case GPM_B_MIDDLE: + selection_paste(); + break; + + case GPM_B_RIGHT: + if (three_button_mode == 1) + selection_copy(x1, y1, x2, y2, event->clicks); + else + selection_paste(); + break; + } + } +} + +/*-------------------------------------------------------------------*/ +void selection_disable_paste(void) +{ + sel_opts.aged = 1; +} diff -Nru a/src/startup.c b/src/startup.c --- a/src/startup.c 2004-08-10 01:18:02 -05:00 +++ b/src/startup.c 2004-08-10 01:18:02 -05:00 @@ -36,6 +36,7 @@ #include "headers/gpmInt.h" #include "headers/message.h" #include "headers/console.h" +#include "headers/selection.h" /* what todo atexit */ static void gpm_exited(void) @@ -55,8 +56,7 @@ option.autodetect = 0; /* no mouse autodection */ option.progname = argv[0]; /* who we are */ - console.device = Gpm_get_console(); /* get consolename */ - + get_console_name(); cmdline(argc, argv); /* parse command line */ if (geteuid() != 0) gpm_report(GPM_PR_OOPS,GPM_MESS_ROOT); /* root or exit */ diff -Nru a/src/tools.c b/src/tools.c --- a/src/tools.c 2004-08-10 01:18:01 -05:00 +++ /dev/null Wed Dec 31 16:00:00 196900 @@ -1,81 +0,0 @@ -/* - * tools.c - tools which are needed by client and server - * - * Copyright (c) 2001 Nico Schottelius <nico@xxxxxxxxxxxxxxx> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - ********/ - -#include <stdio.h> /* NULL */ -#include <string.h> -#include <stdlib.h> -#include <sys/types.h> /* these three are */ -#include <sys/stat.h> /* needed for */ -#include <unistd.h> /* stat() */ - -#include "headers/gpmInt.h" /* only used for some defines */ - -/***************************************************************************** - * check, whether devfs is used or not. - * See /usr/src/linux/Documentation/filesystems/devfs/ for details. - * Returns: the name of the console (/dev/tty0 or /dev/vc/0) - *****************************************************************************/ -char *Gpm_get_console(void) -{ - struct stat buf; - - /* first try the devfs device, because in the next time this will be - * the preferred one. If that fails, take the old console */ - - /* Check for open new console */ - if (stat(GPM_DEVFS_CONSOLE, &buf) == 0) - return strdup(GPM_DEVFS_CONSOLE); - - /* Failed, try OLD console */ - else if (stat(GPM_OLD_CONSOLE, &buf) == 0) - return strdup(GPM_OLD_CONSOLE); - - return NULL; -} - -/* what's the english name for potenz ? */ -int Gpm_x_high_y(int base, int pot_y) -{ - int val = 1; - - if (pot_y == 0) val = 1; - else if (pot_y < 0) val = 0; /* ugly hack ;) */ - else while(pot_y > 0) { - val = val * base; - pot_y--; - } - return val; -} - -/* return characters needed to display int */ -int Gpm_cnt_digits(int number) -{ - /* 0-9 = 1 10^0 <-> (10^1)-1 - * 10 - 99 = 2 10^1 <-> (10^2)-1 - * 100 - 999 = 3 10^2 <-> (10^3)-1 - * 1000 - 9999 = 4 ... */ - - int digits = 1; - - while ((number /= 10)) - digits++; - - return digits; -} _______________________________________________ gpm mailing list gpm@xxxxxxxxxxxxxx http://lists.linux.it/listinfo/gpm