/* Tracking areas. Copyright (C) 2001 Johan Rydberg. All Rights Reserved. This file is part of Crust. 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 #include "priv.h" #include "crust-client.h" static CFTypeID SFTrackingAreaTypeID; /* CoreFoundation runtime class for SFTrackingArea. */ static CFRuntimeClass SFTrackingAreaRuntimeClass = { 0, /* version */ "SFTrackingArea", /* Name of class. */ sizeof (struct SFTrackingArea), /* Instance size. */ 0, /* Init function. */ 0 /* Final function. */ }; static void initialize_trackingarea_runtime (void) __attribute__ ((constructor)); /* Initialize runtime class for SFTrackingArea. This has a "constructor" attribute so that is should be called at initialization time. */ static void initialize_trackingarea_runtime (void) { SFTrackingAreaTypeID = CFRuntimeRegisterClass (&SFTrackingAreaRuntimeClass); } SFTrackingAreaRef SXTrackingAreaCreate (SFSurfaceRef surface, GFRect area, unsigned int event_mask, void *user_data) { SFTrackingAreaRef tracking_area; unsigned int real_event_mask = event_mask; /* Things that need to be done here: . check if we fail to allocate instance, . and clip area after surface. */ tracking_area = CFRuntimeCreateInstance (SFTrackingAreaTypeID); tracking_area->area = area; tracking_area->event_mask = event_mask; tracking_area->surface = surface; tracking_area->user_data = user_data; /* Insert tracking area into surface's list of tracking areas. */ CFArrayAppend (surface->track_array, tracking_area); /* ??? this is pretty ugly - should not access the member direct. */ if (event_mask & (kSFEventMouseEnteredMask | kSFEventMouseExitedMask)) real_event_mask |= kSFEventMouseMovedMask; SFSurfaceSetEventMask (surface, surface->event_mask | real_event_mask); return tracking_area; } void * SFTrackingAreaUserData (SFTrackingAreaRef tracking_area) { return tracking_area->user_data; } void SFTrackingAreaGrabCursor (SFTrackingAreaRef tracking_area) { SFSurfaceRef surface = tracking_area->surface; int err; if (surface->track_cursor) { CFLog ("*** SFTrackingAreaGrabCursor: Cursor already grabbed\n"); return; } err = _surface_cursor_grab (surface->surface_port); if (err) { CFLog ("*** SFTrackingAreaGrabCursor: Failed to grab cursor: %d\n", err); return; } surface->track_cursor = tracking_area; } void SFTrackingAreaUngrabCursor (SFTrackingAreaRef tracking_area) { SFSurfaceRef surface = tracking_area->surface; int err; if (surface->track_cursor != tracking_area) { CFLog ("*** SFTrackingAreaUngrabCursor: Ungrab by invalid area\n"); return; } surface->track_cursor = 0; err = _surface_cursor_ungrab (surface->surface_port); if (err) { CFLog ("*** SFTrackingAreaUngrabCursor: Failed to ungrab cursor: %d\n", err); return; } }