Commit 7fa13eaf authored by Alexander Larsson's avatar Alexander Larsson Committed by Alexander Larsson

Add gdkmouse-fb.c

2000-12-06  Alexander Larsson  <alexl@redhat.com>

	* gdk/linux-fb/Makefile.am:
	Add gdkmouse-fb.c

	* gdk/linux-fb/gdkmouse-fb.c:
	New file. Abstracted the mouse drivers a bit.

	* gdk/linux-fb/gdkcursor-fb.c:
	The cursor hide/show functions was moved here from gdkinput-ps2.c.

	* gdk/linux-fb/gdkinput-ps2.c:
	Removed old mouse handling code. Moved cursor handling code
	to gdkcursor-fb.c, moved gdk_fb_window_send_crossing_events() to
	gdkwindow-fb.c. gdk_input_get_mouseinfo was renamed to
	gdk_mouse_get_info.

	* gdk/linux-fb/gdkmain-fb.c:
	Pass NULL pointers for x,y in gdk_mouse_get_info call.

	* gdk/linux-fb/gdkprivate-fb.h:
	Removed public gdk_fb_find_common_ancestor, added and renamed
	functions for the new mouse handling code.

	* gdk/linux-fb/gdkwindow-fb.c:
	Moved gdk_fb_window_send_crossing_events here. added global
	variable gdk_fb_window_containing_pointer. made
	gdk_fb_find_common_ancestor static. gdk_input_get_mouseinfo was
	renamed to gdk_mouse_get_info.
parent f71ea1c0
2000-12-06 Alexander Larsson <alexl@redhat.com>
* gdk/linux-fb/Makefile.am:
Add gdkmouse-fb.c
* gdk/linux-fb/gdkmouse-fb.c:
New file. Abstracted the mouse drivers a bit.
* gdk/linux-fb/gdkcursor-fb.c:
The cursor hide/show functions was moved here from gdkinput-ps2.c.
* gdk/linux-fb/gdkinput-ps2.c:
Removed old mouse handling code. Moved cursor handling code
to gdkcursor-fb.c, moved gdk_fb_window_send_crossing_events() to
gdkwindow-fb.c. gdk_input_get_mouseinfo was renamed to
gdk_mouse_get_info.
* gdk/linux-fb/gdkmain-fb.c:
Pass NULL pointers for x,y in gdk_mouse_get_info call.
* gdk/linux-fb/gdkprivate-fb.h:
Removed public gdk_fb_find_common_ancestor, added and renamed
functions for the new mouse handling code.
* gdk/linux-fb/gdkwindow-fb.c:
Moved gdk_fb_window_send_crossing_events here. added global
variable gdk_fb_window_containing_pointer. made
gdk_fb_find_common_ancestor static. gdk_input_get_mouseinfo was
renamed to gdk_mouse_get_info.
2000-12-06 Alexander Larsson <alexl@redhat.com>
* gdk/linux-fb/gdkevents-fb.c:
......
2000-12-06 Alexander Larsson <alexl@redhat.com>
* gdk/linux-fb/Makefile.am:
Add gdkmouse-fb.c
* gdk/linux-fb/gdkmouse-fb.c:
New file. Abstracted the mouse drivers a bit.
* gdk/linux-fb/gdkcursor-fb.c:
The cursor hide/show functions was moved here from gdkinput-ps2.c.
* gdk/linux-fb/gdkinput-ps2.c:
Removed old mouse handling code. Moved cursor handling code
to gdkcursor-fb.c, moved gdk_fb_window_send_crossing_events() to
gdkwindow-fb.c. gdk_input_get_mouseinfo was renamed to
gdk_mouse_get_info.
* gdk/linux-fb/gdkmain-fb.c:
Pass NULL pointers for x,y in gdk_mouse_get_info call.
* gdk/linux-fb/gdkprivate-fb.h:
Removed public gdk_fb_find_common_ancestor, added and renamed
functions for the new mouse handling code.
* gdk/linux-fb/gdkwindow-fb.c:
Moved gdk_fb_window_send_crossing_events here. added global
variable gdk_fb_window_containing_pointer. made
gdk_fb_find_common_ancestor static. gdk_input_get_mouseinfo was
renamed to gdk_mouse_get_info.
2000-12-06 Alexander Larsson <alexl@redhat.com>
* gdk/linux-fb/gdkevents-fb.c:
......
2000-12-06 Alexander Larsson <alexl@redhat.com>
* gdk/linux-fb/Makefile.am:
Add gdkmouse-fb.c
* gdk/linux-fb/gdkmouse-fb.c:
New file. Abstracted the mouse drivers a bit.
* gdk/linux-fb/gdkcursor-fb.c:
The cursor hide/show functions was moved here from gdkinput-ps2.c.
* gdk/linux-fb/gdkinput-ps2.c:
Removed old mouse handling code. Moved cursor handling code
to gdkcursor-fb.c, moved gdk_fb_window_send_crossing_events() to
gdkwindow-fb.c. gdk_input_get_mouseinfo was renamed to
gdk_mouse_get_info.
* gdk/linux-fb/gdkmain-fb.c:
Pass NULL pointers for x,y in gdk_mouse_get_info call.
* gdk/linux-fb/gdkprivate-fb.h:
Removed public gdk_fb_find_common_ancestor, added and renamed
functions for the new mouse handling code.
* gdk/linux-fb/gdkwindow-fb.c:
Moved gdk_fb_window_send_crossing_events here. added global
variable gdk_fb_window_containing_pointer. made
gdk_fb_find_common_ancestor static. gdk_input_get_mouseinfo was
renamed to gdk_mouse_get_info.
2000-12-06 Alexander Larsson <alexl@redhat.com>
* gdk/linux-fb/gdkevents-fb.c:
......
2000-12-06 Alexander Larsson <alexl@redhat.com>
* gdk/linux-fb/Makefile.am:
Add gdkmouse-fb.c
* gdk/linux-fb/gdkmouse-fb.c:
New file. Abstracted the mouse drivers a bit.
* gdk/linux-fb/gdkcursor-fb.c:
The cursor hide/show functions was moved here from gdkinput-ps2.c.
* gdk/linux-fb/gdkinput-ps2.c:
Removed old mouse handling code. Moved cursor handling code
to gdkcursor-fb.c, moved gdk_fb_window_send_crossing_events() to
gdkwindow-fb.c. gdk_input_get_mouseinfo was renamed to
gdk_mouse_get_info.
* gdk/linux-fb/gdkmain-fb.c:
Pass NULL pointers for x,y in gdk_mouse_get_info call.
* gdk/linux-fb/gdkprivate-fb.h:
Removed public gdk_fb_find_common_ancestor, added and renamed
functions for the new mouse handling code.
* gdk/linux-fb/gdkwindow-fb.c:
Moved gdk_fb_window_send_crossing_events here. added global
variable gdk_fb_window_containing_pointer. made
gdk_fb_find_common_ancestor static. gdk_input_get_mouseinfo was
renamed to gdk_mouse_get_info.
2000-12-06 Alexander Larsson <alexl@redhat.com>
* gdk/linux-fb/gdkevents-fb.c:
......
2000-12-06 Alexander Larsson <alexl@redhat.com>
* gdk/linux-fb/Makefile.am:
Add gdkmouse-fb.c
* gdk/linux-fb/gdkmouse-fb.c:
New file. Abstracted the mouse drivers a bit.
* gdk/linux-fb/gdkcursor-fb.c:
The cursor hide/show functions was moved here from gdkinput-ps2.c.
* gdk/linux-fb/gdkinput-ps2.c:
Removed old mouse handling code. Moved cursor handling code
to gdkcursor-fb.c, moved gdk_fb_window_send_crossing_events() to
gdkwindow-fb.c. gdk_input_get_mouseinfo was renamed to
gdk_mouse_get_info.
* gdk/linux-fb/gdkmain-fb.c:
Pass NULL pointers for x,y in gdk_mouse_get_info call.
* gdk/linux-fb/gdkprivate-fb.h:
Removed public gdk_fb_find_common_ancestor, added and renamed
functions for the new mouse handling code.
* gdk/linux-fb/gdkwindow-fb.c:
Moved gdk_fb_window_send_crossing_events here. added global
variable gdk_fb_window_containing_pointer. made
gdk_fb_find_common_ancestor static. gdk_input_get_mouseinfo was
renamed to gdk_mouse_get_info.
2000-12-06 Alexander Larsson <alexl@redhat.com>
* gdk/linux-fb/gdkevents-fb.c:
......
2000-12-06 Alexander Larsson <alexl@redhat.com>
* gdk/linux-fb/Makefile.am:
Add gdkmouse-fb.c
* gdk/linux-fb/gdkmouse-fb.c:
New file. Abstracted the mouse drivers a bit.
* gdk/linux-fb/gdkcursor-fb.c:
The cursor hide/show functions was moved here from gdkinput-ps2.c.
* gdk/linux-fb/gdkinput-ps2.c:
Removed old mouse handling code. Moved cursor handling code
to gdkcursor-fb.c, moved gdk_fb_window_send_crossing_events() to
gdkwindow-fb.c. gdk_input_get_mouseinfo was renamed to
gdk_mouse_get_info.
* gdk/linux-fb/gdkmain-fb.c:
Pass NULL pointers for x,y in gdk_mouse_get_info call.
* gdk/linux-fb/gdkprivate-fb.h:
Removed public gdk_fb_find_common_ancestor, added and renamed
functions for the new mouse handling code.
* gdk/linux-fb/gdkwindow-fb.c:
Moved gdk_fb_window_send_crossing_events here. added global
variable gdk_fb_window_containing_pointer. made
gdk_fb_find_common_ancestor static. gdk_input_get_mouseinfo was
renamed to gdk_mouse_get_info.
2000-12-06 Alexander Larsson <alexl@redhat.com>
* gdk/linux-fb/gdkevents-fb.c:
......
2000-12-06 Alexander Larsson <alexl@redhat.com>
* gdk/linux-fb/Makefile.am:
Add gdkmouse-fb.c
* gdk/linux-fb/gdkmouse-fb.c:
New file. Abstracted the mouse drivers a bit.
* gdk/linux-fb/gdkcursor-fb.c:
The cursor hide/show functions was moved here from gdkinput-ps2.c.
* gdk/linux-fb/gdkinput-ps2.c:
Removed old mouse handling code. Moved cursor handling code
to gdkcursor-fb.c, moved gdk_fb_window_send_crossing_events() to
gdkwindow-fb.c. gdk_input_get_mouseinfo was renamed to
gdk_mouse_get_info.
* gdk/linux-fb/gdkmain-fb.c:
Pass NULL pointers for x,y in gdk_mouse_get_info call.
* gdk/linux-fb/gdkprivate-fb.h:
Removed public gdk_fb_find_common_ancestor, added and renamed
functions for the new mouse handling code.
* gdk/linux-fb/gdkwindow-fb.c:
Moved gdk_fb_window_send_crossing_events here. added global
variable gdk_fb_window_containing_pointer. made
gdk_fb_find_common_ancestor static. gdk_input_get_mouseinfo was
renamed to gdk_mouse_get_info.
2000-12-06 Alexander Larsson <alexl@redhat.com>
* gdk/linux-fb/gdkevents-fb.c:
......
......@@ -50,6 +50,7 @@ libgdk_linux_fb_la_SOURCES = \
gdkprivate-fb.h \
gdkinputprivate.h \
gdkinput-ps2.c \
gdkmouse-fb.c \
gdkevents-fb.c \
gdkrender-fb.c \
mi.h \
......
......@@ -284,3 +284,239 @@ _gdk_cursor_destroy (GdkCursor *cursor)
g_free (private);
}
/* Global data to keep track of cursor */
static GdkPixmap *last_contents = NULL;
static GdkPoint last_location, last_contents_size;
static GdkCursor *last_cursor = NULL;
static GdkFBDrawingContext *gdk_fb_cursor_dc = NULL;
static GdkFBDrawingContext cursor_dc_dat;
static GdkGC *cursor_gc;
static gint cursor_visibility_count = 1;
static GdkFBDrawingContext *
gdk_fb_cursor_dc_reset (void)
{
if (gdk_fb_cursor_dc)
gdk_fb_drawing_context_finalize (gdk_fb_cursor_dc);
gdk_fb_cursor_dc = &cursor_dc_dat;
gdk_fb_drawing_context_init (gdk_fb_cursor_dc,
GDK_DRAWABLE_IMPL(gdk_parent_root),
cursor_gc,
TRUE,
FALSE);
return gdk_fb_cursor_dc;
}
void
gdk_fb_cursor_hide (void)
{
GdkFBDrawingContext *mydc = gdk_fb_cursor_dc;
cursor_visibility_count--;
g_assert (cursor_visibility_count <= 0);
if (cursor_visibility_count < 0)
return;
if (!mydc)
mydc = gdk_fb_cursor_dc_reset ();
if (last_contents)
{
gdk_gc_set_clip_mask (cursor_gc, NULL);
/* Restore old picture */
gdk_fb_draw_drawable_3 (GDK_DRAWABLE_IMPL(gdk_parent_root),
cursor_gc,
GDK_DRAWABLE_IMPL(last_contents),
mydc,
0, 0,
last_location.x,
last_location.y,
last_contents_size.x,
last_contents_size.y);
}
}
void
gdk_fb_cursor_invalidate (void)
{
if (last_contents)
{
gdk_pixmap_unref (last_contents);
last_contents = NULL;
}
}
void
gdk_fb_cursor_unhide()
{
GdkFBDrawingContext *mydc = gdk_fb_cursor_dc;
GdkCursorPrivateFB *last_private;
GdkDrawableFBData *pixmap_last;
last_private = GDK_CURSOR_FB (last_cursor);
pixmap_last = GDK_DRAWABLE_IMPL_FBDATA (last_private->cursor);
cursor_visibility_count++;
g_assert (cursor_visibility_count <= 1);
if (cursor_visibility_count < 1)
return;
if (!mydc)
mydc = gdk_fb_cursor_dc_reset ();
if (last_cursor)
{
if (!last_contents ||
pixmap_last->width > GDK_DRAWABLE_IMPL_FBDATA (last_contents)->width ||
pixmap_last->height > GDK_DRAWABLE_IMPL_FBDATA (last_contents)->height)
{
if (last_contents)
gdk_pixmap_unref (last_contents);
last_contents = gdk_pixmap_new (gdk_parent_root,
pixmap_last->width,
pixmap_last->height,
GDK_DRAWABLE_IMPL_FBDATA (gdk_parent_root)->depth);
}
gdk_gc_set_clip_mask (cursor_gc, NULL);
gdk_fb_draw_drawable_2 (GDK_DRAWABLE_IMPL (last_contents),
cursor_gc,
GDK_DRAWABLE_IMPL (gdk_parent_root),
last_location.x,
last_location.y,
0, 0,
pixmap_last->width,
pixmap_last->height,
TRUE, FALSE);
last_contents_size.x = pixmap_last->width;
last_contents_size.y = pixmap_last->height;
gdk_gc_set_clip_mask (cursor_gc, last_private->mask);
gdk_gc_set_clip_origin (cursor_gc,
last_location.x,
last_location.y);
gdk_fb_cursor_dc_reset ();
gdk_fb_draw_drawable_3 (GDK_DRAWABLE_IMPL (gdk_parent_root),
cursor_gc,
GDK_DRAWABLE_IMPL (last_private->cursor),
mydc,
0, 0,
last_location.x, last_location.y,
pixmap_last->width,
pixmap_last->height);
}
else
gdk_fb_cursor_invalidate ();
}
gboolean
gdk_fb_cursor_region_need_hide (GdkRegion *region)
{
GdkRectangle testme;
if (!last_cursor)
return FALSE;
testme.x = last_location.x;
testme.y = last_location.y;
testme.width = GDK_DRAWABLE_IMPL_FBDATA (GDK_CURSOR_FB (last_cursor)->cursor)->width;
testme.height = GDK_DRAWABLE_IMPL_FBDATA (GDK_CURSOR_FB (last_cursor)->cursor)->height;
return (gdk_region_rect_in (region, &testme) != GDK_OVERLAP_RECTANGLE_OUT);
}
gboolean
gdk_fb_cursor_need_hide (GdkRectangle *rect)
{
GdkRectangle testme;
if (!last_cursor)
return FALSE;
testme.x = last_location.x;
testme.y = last_location.y;
testme.width = GDK_DRAWABLE_IMPL_FBDATA (GDK_CURSOR_FB (last_cursor)->cursor)->width;
testme.height = GDK_DRAWABLE_IMPL_FBDATA (GDK_CURSOR_FB (last_cursor)->cursor)->height;
return gdk_rectangle_intersect (rect, &testme, &testme);
}
void
gdk_fb_get_cursor_rect (GdkRectangle *rect)
{
if (last_cursor)
{
rect->x = last_location.x;
rect->y = last_location.y;
rect->width = GDK_DRAWABLE_IMPL_FBDATA (GDK_CURSOR_FB (last_cursor)->cursor)->width;
rect->height = GDK_DRAWABLE_IMPL_FBDATA (GDK_CURSOR_FB (last_cursor)->cursor)->height;
}
else
{
rect->x = rect->y = -1;
rect->width = rect->height = 0;
}
}
void
gdk_fb_cursor_move (gint x, gint y, GdkWindow *in_window)
{
GdkCursor *the_cursor;
if (!cursor_gc)
{
GdkColor white, black;
cursor_gc = gdk_gc_new (gdk_parent_root);
gdk_color_black (gdk_colormap_get_system (), &black);
gdk_color_white (gdk_colormap_get_system (), &white);
gdk_gc_set_foreground (cursor_gc, &black);
gdk_gc_set_background (cursor_gc, &white);
}
gdk_fb_cursor_hide ();
if (_gdk_fb_pointer_grab_window)
{
if (_gdk_fb_pointer_grab_cursor)
the_cursor = _gdk_fb_pointer_grab_cursor;
else
{
GdkWindow *win = _gdk_fb_pointer_grab_window;
while (!GDK_WINDOW_IMPL_FBDATA (win)->cursor && GDK_WINDOW_OBJECT (win)->parent)
win = (GdkWindow *)GDK_WINDOW_OBJECT (win)->parent;
the_cursor = GDK_WINDOW_IMPL_FBDATA (win)->cursor;
}
}
else
{
while (!GDK_WINDOW_IMPL_FBDATA (in_window)->cursor && GDK_WINDOW_P (in_window)->parent)
in_window = (GdkWindow *)GDK_WINDOW_P (in_window)->parent;
the_cursor = GDK_WINDOW_IMPL_FBDATA (in_window)->cursor;
}
last_location.x = x - GDK_CURSOR_FB (the_cursor)->hot_x;
last_location.y = y - GDK_CURSOR_FB (the_cursor)->hot_y;
if (the_cursor)
gdk_cursor_ref (the_cursor);
if (last_cursor)
gdk_cursor_unref (last_cursor);
last_cursor = the_cursor;
gdk_fb_cursor_unhide ();
}
void
gdk_fb_cursor_reset(void)
{
GdkWindow *win = gdk_window_at_pointer (NULL, NULL);
gint x, y;
gdk_mouse_get_info (&x, &y, NULL);
gdk_fb_cursor_move (x, y, win);
}
This diff is collapsed.
......@@ -966,10 +966,9 @@ gdk_event_make (GdkWindow *window,
if (evmask & (GDK_BUTTON1_MOTION_MASK|GDK_BUTTON2_MOTION_MASK|GDK_BUTTON3_MOTION_MASK))
{
gint x, y;
GdkModifierType mask;
gdk_input_get_mouseinfo (&x, &y, &mask);
gdk_mouse_get_info (NULL, NULL, &mask);
if (((mask & GDK_BUTTON1_MASK) && (evmask & GDK_BUTTON1_MOTION_MASK)) ||
((mask & GDK_BUTTON2_MASK) && (evmask & GDK_BUTTON2_MOTION_MASK)) ||
......
#include <gdk/gdk.h>
#include <gdk/gdkinternals.h>
#include "gdkprivate-fb.h"
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <string.h>
#include <math.h>
typedef struct _GdkFBMouse GdkFBMouse;
typedef struct _GdkFBMouseDevice GdkFBMouseDevice;
struct _GdkFBMouse {
gint fd; /* Set by open */
/* These are written to by parse_packet */
gdouble x, y;
gboolean button_pressed[3];
guchar mouse_packet[5]; /* read by parse_packet */
gint packet_nbytes;
gboolean click_grab;
GIOChannel *io;
gint io_tag;
GdkFBMouseDevice *dev;
};
static GdkFBMouse *gdk_fb_mouse = NULL;
void
gdk_mouse_get_info (gint *x,
gint *y,
GdkModifierType *mask)
{
if (x)
*x = gdk_fb_mouse->x;
if (y)
*y = gdk_fb_mouse->y;
if (mask)
*mask =
(gdk_fb_mouse->button_pressed[0]?GDK_BUTTON1_MASK:0) |
(gdk_fb_mouse->button_pressed[1]?GDK_BUTTON2_MASK:0) |
(gdk_fb_mouse->button_pressed[2]?GDK_BUTTON3_MASK:0) |
/*keyboard->modifier_state*/0; //TODO
}
static void
handle_mouse_movement(GdkFBMouse *mouse)
{
GdkWindow *mousewin;
GdkEvent *event;
gint x, y;
GdkWindow *win, *grabwin;
guint state;
GdkDrawableFBData *mousewin_private;
if (_gdk_fb_pointer_grab_confine)
mousewin = _gdk_fb_pointer_grab_confine;
else
mousewin = gdk_parent_root;
mousewin_private = GDK_DRAWABLE_IMPL_FBDATA (mousewin);
if (mouse->x < mousewin_private->llim_x)
mouse->x = mousewin_private->llim_x;
else if (mouse->x > mousewin_private->lim_x - 1)
mouse->x = mousewin_private->lim_x - 1;
if (mouse->y < mousewin_private->llim_y)
mouse->y = mousewin_private->llim_y;
else if (mouse->y > mousewin_private->lim_y - 1)
mouse->y = mousewin_private->lim_y - 1;
win = gdk_window_at_pointer (NULL, NULL);
if (_gdk_fb_pointer_grab_window_events)
grabwin = _gdk_fb_pointer_grab_window_events;
else
grabwin = win;
gdk_fb_cursor_move (mouse->x, mouse->y, grabwin);
gdk_window_get_origin (grabwin, &x, &y);
x = mouse->x - x;
y = mouse->y - y;
state = (mouse->button_pressed[0]?GDK_BUTTON1_MASK:0) |
(mouse->button_pressed[1]?GDK_BUTTON2_MASK:0) |
(mouse->button_pressed[2]?GDK_BUTTON3_MASK:0) |
/*keyboard->modifier_state*/0; // TODO
event = gdk_event_make (grabwin, GDK_MOTION_NOTIFY, TRUE);
if (event)
{
event->motion.x = x;
event->motion.y = y;
event->motion.state = state;
event->motion.is_hint = FALSE;
event->motion.device = gdk_core_pointer;
event->motion.x_root = mouse->x;
event->motion.y_root = mouse->y;
}
gdk_fb_window_send_crossing_events (win, GDK_CROSSING_NORMAL);
}
static void
send_button_event (GdkFBMouse *mouse,
guint button,
gboolean press_event)
{
GdkEvent *event;
gint x, y, i;
GdkWindow *window;
int nbuttons;
if (_gdk_fb_pointer_grab_window_events)
window = _gdk_fb_pointer_grab_window_events;
else
window = gdk_window_at_pointer(NULL, NULL);
event = gdk_event_make (window, press_event ? GDK_BUTTON_PRESS : GDK_BUTTON_RELEASE, FALSE);
if (event)
{
gdk_window_get_origin (window, &x, &y);
x = mouse->x - x;
y = mouse->y - y;
event->button.x = x;
event->button.y = y;
event->button.button = button;
event->button.state = (mouse->button_pressed[0]?GDK_BUTTON1_MASK:0) |
(mouse->button_pressed[1] ? GDK_BUTTON2_MASK : 0) |
(mouse->button_pressed[2] ? GDK_BUTTON3_MASK : 0) |
(1 << (button + 8)) /* badhack */ |
/*keyboard->modifier_state*/0; // TODO
event->button.device = gdk_core_pointer;
event->button.x_root = mouse->x;
event->button.y_root = mouse->y;
gdk_event_queue_append (event);
/* For double-clicks */
if (press_event)
gdk_event_button_generate (event);
}