📄 gdkmouse-fb.c
字号:
} mouse->packet_nbytes += n; if (mouse->packet_nbytes == dev->packet_size) { if (dev->parse_packet (mouse, &got_motion)) mouse->packet_nbytes = 0; } } if (got_motion) handle_mouse_movement (mouse); return TRUE;}static gintgdk_fb_mouse_dev_open (char *devname, gint mode){ gint fd; /* Use nonblocking mode to open, to not hang on device */ fd = open (devname, mode | O_NONBLOCK); return fd;}static gbooleanwrite_all (gint fd, gchar *buf, gsize to_write){ while (to_write > 0) { gssize count = write (fd, buf, to_write); if (count < 0) { if (errno != EINTR) return FALSE; } else { to_write -= count; buf += count; } } return TRUE;}static gbooleangdk_fb_mouse_ps2_open (GdkFBMouse *mouse){ gint fd; guchar buf[7]; int i = 0; fd = gdk_fb_mouse_dev_open (mouse->file, O_RDWR); if (fd < 0) { g_print ("Error opening %s: %s\n", mouse->file, strerror (errno)); return FALSE; } /* From xf86_Mouse.c */ buf[i++] = 230; /* 1:1 scaling */ buf[i++] = 244; /* enable mouse */ buf[i++] = 243; /* Sample rate */ buf[i++] = 200; buf[i++] = 232; /* device resolution */ buf[i++] = 1; if (!write_all (fd, buf, i)) { close (fd); return FALSE; } usleep (10000); /* sleep 10 ms, then read whatever junk we can get from the mouse, in a vain attempt to get synchronized with the event stream */ while ((i = read (fd, buf, sizeof(buf))) > 0) g_print ("Got %d bytes of junk from psaux\n", i); mouse->fd = fd; return TRUE;}static gbooleangdk_fb_mouse_imps2_open (GdkFBMouse *mouse){ gint fd; guchar buf[7]; int i = 0; fd = gdk_fb_mouse_dev_open (mouse->file, O_RDWR); if (fd < 0) { g_print ("Error opening %s: %s\n", mouse->file, strerror (errno)); return FALSE; } i = 0; buf[i++] = 243; /* Sample rate */ buf[i++] = 200; buf[i++] = 243; /* Sample rate */ buf[i++] = 100; buf[i++] = 243; /* Sample rate */ buf[i++] = 80; buf[i++] = 242; if (!write_all (fd, buf, i)) { close (fd); return FALSE; } if (read (fd, buf, 1) != 1) { close (fd); return FALSE; } i = 0; buf[i++] = 230; /* 1:1 scaling */ buf[i++] = 244; /* enable mouse */ buf[i++] = 243; /* Sample rate */ buf[i++] = 100; buf[i++] = 232; /* device resolution */ buf[i++] = 3; if (!write_all (fd, buf, i)) { close (fd); return FALSE; } mouse->fd = fd; return TRUE;}static voidgdk_fb_mouse_ps2_close (GdkFBMouse *mouse){ close (mouse->fd); mouse->fd = -1;}static gbooleangdk_fb_mouse_ps2_packet (GdkFBMouse *mouse, gboolean *got_motion){ int dx=0, dy=0; gboolean new_button1, new_button2, new_button3; guchar *buf; buf = mouse->mouse_packet; new_button1 = (buf[0] & 1) && 1; new_button3 = (buf[0] & 2) && 1; new_button2 = (buf[0] & 4) && 1; if (mouse->dev->packet_size == 4 && buf[3] != 0) handle_mouse_scroll (mouse, buf[3] & 0x80); if (*got_motion && (new_button1 != mouse->button_pressed[0] || new_button2 != mouse->button_pressed[1] || new_button3 != mouse->button_pressed[2])) { /* If a mouse button state changes we need to get correct ordering with enter/leave events, so push those out via handle_mouse_input */ *got_motion = FALSE; handle_mouse_movement (mouse); } if (new_button1 != mouse->button_pressed[0]) { mouse->button_pressed[0] = new_button1; send_button_event (mouse, 1, new_button1); } if (new_button2 != mouse->button_pressed[1]) { mouse->button_pressed[1] = new_button2; send_button_event (mouse, 2, new_button2); } if (new_button3 != mouse->button_pressed[2]) { mouse->button_pressed[2] = new_button3; send_button_event (mouse, 3, new_button3); } if (buf[1] != 0) dx = ((buf[0] & 0x10) ? ((gint)buf[1])-256 : buf[1]); else dx = 0; if (buf[2] != 0) dy = -((buf[0] & 0x20) ? ((gint)buf[2])-256 : buf[2]); else dy = 0; mouse->x += dx; mouse->y += dy; if (dx || dy) *got_motion = TRUE; return TRUE;}static gbooleangdk_fb_mouse_ms_open (GdkFBMouse *mouse){ gint fd; gint i; guchar buf[7]; struct termios tty; fd = gdk_fb_mouse_dev_open (mouse->file, O_RDWR); if (fd < 0) { g_print ("Error opening %s: %s\n", mouse->file, strerror (errno)); return FALSE; } while ((i = read (fd, buf, sizeof(buf))) > 0) g_print ("Got %d bytes of junk from %s\n", i, mouse->file); tcgetattr (fd, &tty); tty.c_iflag = IGNBRK | IGNPAR; tty.c_cflag = CREAD|CLOCAL|HUPCL|CS7|B1200; tty.c_oflag = 0; tty.c_lflag = 0; tty.c_line = 0; tty.c_cc[VTIME] = 0; tty.c_cc[VMIN] = 1; tcsetattr (fd, TCSAFLUSH, &tty); if (!write_all (fd, "*n", 2)) { close (fd); return FALSE; } mouse->fd = fd; return TRUE;}static voidgdk_fb_mouse_ms_close (GdkFBMouse *mouse){ close (mouse->fd); mouse->fd = -1;}static gbooleangdk_fb_mouse_ms_packet (GdkFBMouse *mouse, gboolean *got_motion){ int dx=0, dy=0; gboolean new_button1, new_button2, new_button3; guchar *buf; static guchar prev = 0; buf = mouse->mouse_packet; /* handling of third button is adapted from gpm ms driver */ if (buf[0] == 0x40 && !(prev|buf[1]|buf[2])) { new_button1 = 0; new_button2 = 1; new_button3 = 0; } else { new_button1 = (buf[0] & 0x20) && 1; new_button2 = 0; new_button3 = (buf[0] & 0x10) && 1; } prev = (new_button1 << 2) | (new_button2 << 1) | (new_button3 << 0); if (*got_motion && (new_button1 != mouse->button_pressed[0] || new_button2 != mouse->button_pressed[1] || new_button3 != mouse->button_pressed[2])) { /* If a mouse button state changes we need to get correct ordering with enter/leave events, so push those out via handle_mouse_input */ *got_motion = FALSE; handle_mouse_movement (mouse); } if (new_button1 != mouse->button_pressed[0]) { mouse->button_pressed[0] = new_button1; send_button_event (mouse, 1, new_button1); } if (new_button2 != mouse->button_pressed[1]) { mouse->button_pressed[1] = new_button2; send_button_event (mouse, 2, new_button2); } if (new_button3 != mouse->button_pressed[2]) { mouse->button_pressed[2] = new_button3; send_button_event (mouse, 3, new_button3); } dx = (signed char)(((buf[0] & 0x03) << 6) | (buf[1] & 0x3F)); dy = (signed char)(((buf[0] & 0x0C) << 4) | (buf[2] & 0x3F)); mouse->x += dx; mouse->y += dy; if (dx || dy) *got_motion = TRUE; return TRUE;}static gbooleangdk_fb_mouse_fidmour_open (GdkFBMouse *mouse){ gint fd; fd = gdk_fb_mouse_dev_open (mouse->file, O_RDONLY); if (fd < 0) { g_print ("Error opening %s: %s\n", mouse->file, strerror (errno)); return FALSE; } mouse->fd = fd; return TRUE;}static voidgdk_fb_mouse_fidmour_close (GdkFBMouse *mouse){ close (mouse->fd);}static gbooleangdk_fb_mouse_fidmour_packet (GdkFBMouse *mouse, gboolean *got_motion){ int n; gboolean btn_down = 0; gdouble x = 0.0, y = 0.0; n = 0; if (!(mouse->mouse_packet[0] & 0x80)) { int i; /* We haven't received any of the packet yet but there is no header at the beginning */ for (i = 1; i < mouse->packet_nbytes; i++) { if (mouse->mouse_packet[i] & 0x80) { n = i; break; } } } else if (mouse->packet_nbytes > 1 && ((mouse->mouse_packet[0] & 0x90) == 0x90)) { /* eat the 0x90 and following byte, no clue what it's for */ n = 2; } else { switch (mouse->mouse_packet[0] & 0xF) { case 2: btn_down = 0; break; case 1: case 0: btn_down = 1; break; default: g_assert_not_reached (); break; } x = mouse->mouse_packet[1] + (mouse->mouse_packet[2] << 7); if (x > 8192) x -= 16384; y = mouse->mouse_packet[3] + (mouse->mouse_packet[4] << 7); if (y > 8192) y -= 16384; /* Now map touchscreen coords to screen coords */ x *= ((double)gdk_display->fb_width)/4096.0; y *= ((double)gdk_display->fb_height)/4096.0; } if (n) { memmove (mouse->mouse_packet, mouse->mouse_packet+n, mouse->packet_nbytes-n); mouse->packet_nbytes -= n; return FALSE; } if (btn_down != mouse->button_pressed[0]) { if (*got_motion) { /* If a mouse button state changes we need to get correct ordering with enter/leave events, so push those out via handle_mouse_input */ *got_motion = FALSE; handle_mouse_movement (mouse); } mouse->button_pressed[0] = btn_down; send_button_event (mouse, 1, btn_down); } if (fabs(x - mouse->x) >= 1.0 || fabs(x - mouse->y) >= 1.0) { *got_motion = TRUE; mouse->x = x; mouse->y = y; } return TRUE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -