1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
35 #ifdef HAVE_SYS_SELECT_H
36 #include <sys/select.h>
37 #endif /* HAVE_SYS_SELECT_H_ */
39 #define XLIB_ILLEGAL_ACCESS
40 #include <X11/Xatom.h>
43 #include <X11/Xutil.h>
44 #include <X11/Xmu/WinUtil.h>
45 #include <X11/cursorfont.h>
47 #include "gdkprivate.h"
52 #ifndef X_GETTIMEOFDAY
53 #define X_GETTIMEOFDAY(tv) gettimeofday (tv, NULL)
54 #endif /* X_GETTIMEOFDAY */
57 typedef struct _GdkPredicate GdkPredicate;
58 typedef struct _GdkErrorTrap GdkErrorTrap;
73 * Private function declarations
76 #ifndef HAVE_XCONVERTCASE
77 static void gdkx_XConvertCase (KeySym symbol,
80 #define XConvertCase gdkx_XConvertCase
83 static void gdk_exit_func (void);
84 static int gdk_x_error (Display *display,
86 static int gdk_x_io_error (Display *display);
88 GdkFilterReturn gdk_wm_protocols_filter (GdkXEvent *xev,
92 /* Private variable declarations
94 static int gdk_initialized = 0; /* 1 if the library is initialized,
98 static struct timeval start; /* The time at which the library was
101 static struct timeval timer; /* Timeout interval to use in the call
102 * to "select". This is used in
103 * conjunction with "timerp" to create
104 * a maximum time to wait for an event
107 static struct timeval *timerp; /* The actual timer passed to "select"
108 * This may be NULL, in which case
109 * "select" will block until an event
112 static guint32 timer_val; /* The timeout length as specified by
113 * the user in milliseconds.
115 static gint autorepeat;
117 static GSList *gdk_error_traps = NULL; /* List of error traps */
118 static GSList *gdk_error_trap_free_list = NULL; /* Free list */
120 #ifdef G_ENABLE_DEBUG
121 static const GDebugKey gdk_debug_keys[] = {
122 {"events", GDK_DEBUG_EVENTS},
123 {"misc", GDK_DEBUG_MISC},
124 {"dnd", GDK_DEBUG_DND},
125 {"color-context", GDK_DEBUG_COLOR_CONTEXT},
126 {"xim", GDK_DEBUG_XIM}
129 static const int gdk_ndebug_keys = sizeof(gdk_debug_keys)/sizeof(GDebugKey);
131 #endif /* G_ENABLE_DEBUG */
134 *--------------------------------------------------------------
137 * Initialize the library for use.
140 * "argc" is the number of arguments.
141 * "argv" is an array of strings.
144 * "argc" and "argv" are modified to reflect any arguments
145 * which were not handled. (Such arguments should either
146 * be handled by the application or dismissed). If initialization
147 * fails, returns FALSE, otherwise TRUE.
150 * The library is initialized.
152 *--------------------------------------------------------------
156 gdk_init_check (int *argc,
159 XKeyboardState keyboard_state;
162 XClassHint *class_hint;
163 gchar **argv_orig = NULL;
169 if (g_thread_supported ())
170 gdk_threads_mutex = g_mutex_new ();
176 argv_orig = g_malloc ((argc_orig + 1) * sizeof (char*));
177 for (i = 0; i < argc_orig; i++)
178 argv_orig[i] = g_strdup ((*argv)[i]);
179 argv_orig[argc_orig] = NULL;
182 X_GETTIMEOFDAY (&start);
184 gdk_display_name = NULL;
186 XSetErrorHandler (gdk_x_error);
187 XSetIOErrorHandler (gdk_x_io_error);
191 #ifdef G_ENABLE_DEBUG
193 gchar *debug_string = getenv("GDK_DEBUG");
194 if (debug_string != NULL)
195 gdk_debug_flags = g_parse_debug_string (debug_string,
196 (GDebugKey *) gdk_debug_keys,
199 #endif /* G_ENABLE_DEBUG */
207 d = strrchr((*argv)[0],'/');
209 g_set_prgname (d + 1);
211 g_set_prgname ((*argv)[0]);
214 for (i = 1; i < *argc;)
216 #ifdef G_ENABLE_DEBUG
217 if ((strcmp ("--gdk-debug", (*argv)[i]) == 0) ||
218 (strncmp ("--gdk-debug=", (*argv)[i], 12) == 0))
220 gchar *equal_pos = strchr ((*argv)[i], '=');
222 if (equal_pos != NULL)
224 gdk_debug_flags |= g_parse_debug_string (equal_pos+1,
225 (GDebugKey *) gdk_debug_keys,
228 else if ((i + 1) < *argc && (*argv)[i + 1])
230 gdk_debug_flags |= g_parse_debug_string ((*argv)[i+1],
231 (GDebugKey *) gdk_debug_keys,
238 else if ((strcmp ("--gdk-no-debug", (*argv)[i]) == 0) ||
239 (strncmp ("--gdk-no-debug=", (*argv)[i], 15) == 0))
241 gchar *equal_pos = strchr ((*argv)[i], '=');
243 if (equal_pos != NULL)
245 gdk_debug_flags &= ~g_parse_debug_string (equal_pos+1,
246 (GDebugKey *) gdk_debug_keys,
249 else if ((i + 1) < *argc && (*argv)[i + 1])
251 gdk_debug_flags &= ~g_parse_debug_string ((*argv)[i+1],
252 (GDebugKey *) gdk_debug_keys,
260 #endif /* G_ENABLE_DEBUG */
261 if (strcmp ("--display", (*argv)[i]) == 0)
265 if ((i + 1) < *argc && (*argv)[i + 1])
267 gdk_display_name = g_strdup ((*argv)[i + 1]);
268 (*argv)[i + 1] = NULL;
272 else if (strcmp ("--sync", (*argv)[i]) == 0)
277 else if (strcmp ("--no-xshm", (*argv)[i]) == 0)
280 gdk_use_xshm = FALSE;
282 else if (strcmp ("--name", (*argv)[i]) == 0)
284 if ((i + 1) < *argc && (*argv)[i + 1])
287 g_set_prgname ((*argv)[i]);
291 else if (strcmp ("--class", (*argv)[i]) == 0)
293 if ((i + 1) < *argc && (*argv)[i + 1])
296 gdk_progclass = (*argv)[i];
301 else if (strcmp ("--gxid_host", (*argv)[i]) == 0)
303 if ((i + 1) < *argc && (*argv)[i + 1])
306 gdk_input_gxid_host = ((*argv)[i]);
310 else if (strcmp ("--gxid_port", (*argv)[i]) == 0)
312 if ((i + 1) < *argc && (*argv)[i + 1])
315 gdk_input_gxid_port = atoi ((*argv)[i]);
321 else if (strcmp ("--xim-preedit", (*argv)[i]) == 0)
323 if ((i + 1) < *argc && (*argv)[i + 1])
326 if (strcmp ("none", (*argv)[i]) == 0)
327 gdk_im_set_best_style (GDK_IM_PREEDIT_NONE);
328 else if (strcmp ("nothing", (*argv)[i]) == 0)
329 gdk_im_set_best_style (GDK_IM_PREEDIT_NOTHING);
330 else if (strcmp ("area", (*argv)[i]) == 0)
331 gdk_im_set_best_style (GDK_IM_PREEDIT_AREA);
332 else if (strcmp ("position", (*argv)[i]) == 0)
333 gdk_im_set_best_style (GDK_IM_PREEDIT_POSITION);
334 else if (strcmp ("callbacks", (*argv)[i]) == 0)
335 gdk_im_set_best_style (GDK_IM_PREEDIT_CALLBACKS);
338 else if (strcmp ("--xim-status", (*argv)[i]) == 0)
340 if ((i + 1) < *argc && (*argv)[i + 1])
343 if (strcmp ("none", (*argv)[i]) == 0)
344 gdk_im_set_best_style (GDK_IM_STATUS_NONE);
345 else if (strcmp ("nothing", (*argv)[i]) == 0)
346 gdk_im_set_best_style (GDK_IM_STATUS_NOTHING);
347 else if (strcmp ("area", (*argv)[i]) == 0)
348 gdk_im_set_best_style (GDK_IM_STATUS_AREA);
349 else if (strcmp ("callbacks", (*argv)[i]) == 0)
350 gdk_im_set_best_style (GDK_IM_STATUS_CALLBACKS);
358 for (i = 1; i < *argc; i++)
360 for (k = i; k < *argc; k++)
361 if ((*argv)[k] != NULL)
367 for (j = i + k; j < *argc; j++)
368 (*argv)[j-k] = (*argv)[j];
375 g_set_prgname ("<unknown>");
378 GDK_NOTE (MISC, g_message ("progname: \"%s\"", g_get_prgname ()));
380 gdk_display = XOpenDisplay (gdk_display_name);
385 XSynchronize (gdk_display, True);
387 gdk_screen = DefaultScreen (gdk_display);
388 gdk_root_window = RootWindow (gdk_display, gdk_screen);
390 gdk_leader_window = XCreateSimpleWindow(gdk_display, gdk_root_window,
391 10, 10, 10, 10, 0, 0 , 0);
392 class_hint = XAllocClassHint();
393 class_hint->res_name = g_get_prgname ();
394 if (gdk_progclass == NULL)
396 gdk_progclass = g_strdup (g_get_prgname ());
397 gdk_progclass[0] = toupper (gdk_progclass[0]);
399 class_hint->res_class = gdk_progclass;
400 XmbSetWMProperties (gdk_display, gdk_leader_window,
401 NULL, NULL, argv_orig, argc_orig,
402 NULL, NULL, class_hint);
405 for (i = 0; i < argc_orig; i++)
406 g_free(argv_orig[i]);
409 gdk_wm_delete_window = XInternAtom (gdk_display, "WM_DELETE_WINDOW", True);
410 gdk_wm_take_focus = XInternAtom (gdk_display, "WM_TAKE_FOCUS", True);
411 gdk_wm_protocols = XInternAtom (gdk_display, "WM_PROTOCOLS", True);
412 gdk_wm_window_protocols[0] = gdk_wm_delete_window;
413 gdk_wm_window_protocols[1] = gdk_wm_take_focus;
414 gdk_selection_property = XInternAtom (gdk_display, "GDK_SELECTION", False);
416 XGetKeyboardControl (gdk_display, &keyboard_state);
417 autorepeat = keyboard_state.global_auto_repeat;
423 g_atexit (gdk_exit_func);
442 gdk_init (int *argc, char ***argv)
444 if (!gdk_init_check (argc, argv))
446 g_warning ("cannot open display: %s", gdk_get_display ());
452 *--------------------------------------------------------------
455 * Restores the library to an un-itialized state and exits
456 * the program using the "exit" system call.
459 * "errorcode" is the error value to pass to "exit".
462 * Allocated structures are freed and the program exits
467 *--------------------------------------------------------------
471 gdk_exit (gint errorcode)
473 /* de-initialisation is done by the gdk_exit_funct(),
474 no need to do this here (Alex J.) */
479 gdk_set_use_xshm (gint use_xshm)
481 gdk_use_xshm = use_xshm;
485 gdk_get_use_xshm (void)
491 *--------------------------------------------------------------
494 * Get the number of milliseconds since the library was
500 * The time since the library was initialized is returned.
501 * This time value is accurate to milliseconds even though
502 * a more accurate time down to the microsecond could be
507 *--------------------------------------------------------------
514 struct timeval elapsed;
515 guint32 milliseconds;
517 X_GETTIMEOFDAY (&end);
519 if (start.tv_usec > end.tv_usec)
521 end.tv_usec += 1000000;
524 elapsed.tv_sec = end.tv_sec - start.tv_sec;
525 elapsed.tv_usec = end.tv_usec - start.tv_usec;
527 milliseconds = (elapsed.tv_sec * 1000) + (elapsed.tv_usec / 1000);
533 *--------------------------------------------------------------
536 * Returns the current timer.
541 * Returns the current timer interval. This interval is
542 * in units of milliseconds.
546 *--------------------------------------------------------------
556 *--------------------------------------------------------------
559 * Sets the timer interval.
562 * "milliseconds" is the new value for the timer.
567 * Calls to "gdk_event_get" will last for a maximum
568 * of time of "milliseconds". However, a value of 0
569 * milliseconds will cause "gdk_event_get" to block
570 * indefinately until an event is received.
572 *--------------------------------------------------------------
576 gdk_timer_set (guint32 milliseconds)
578 timer_val = milliseconds;
579 timer.tv_sec = milliseconds / 1000;
580 timer.tv_usec = (milliseconds % 1000) * 1000;
585 gdk_timer_enable (void)
591 gdk_timer_disable (void)
597 *--------------------------------------------------------------
600 * Grabs the pointer to a specific window
603 * "window" is the window which will receive the grab
604 * "owner_events" specifies whether events will be reported as is,
605 * or relative to "window"
606 * "event_mask" masks only interesting events
607 * "confine_to" limits the cursor movement to the specified window
608 * "cursor" changes the cursor for the duration of the grab
609 * "time" specifies the time
614 * requires a corresponding call to gdk_pointer_ungrab
616 *--------------------------------------------------------------
620 gdk_pointer_grab (GdkWindow * window,
622 GdkEventMask event_mask,
623 GdkWindow * confine_to,
627 /* From gdkwindow.c */
629 GdkWindowPrivate *window_private;
630 GdkWindowPrivate *confine_to_private;
631 GdkCursorPrivate *cursor_private;
638 g_return_val_if_fail (window != NULL, 0);
640 window_private = (GdkWindowPrivate*) window;
641 confine_to_private = (GdkWindowPrivate*) confine_to;
642 cursor_private = (GdkCursorPrivate*) cursor;
644 xwindow = window_private->xwindow;
646 if (!confine_to || confine_to_private->destroyed)
649 xconfine_to = confine_to_private->xwindow;
654 xcursor = cursor_private->xcursor;
658 for (i = 0; i < gdk_nevent_masks; i++)
660 if (event_mask & (1 << (i + 1)))
661 xevent_mask |= gdk_event_mask_table[i];
664 if (gdk_input_vtable.grab_pointer)
665 return_val = gdk_input_vtable.grab_pointer (window,
671 return_val = Success;
673 if (return_val == Success)
675 if (!window_private->destroyed)
676 return_val = XGrabPointer (window_private->xdisplay,
680 GrabModeAsync, GrabModeAsync,
685 return_val = AlreadyGrabbed;
688 if (return_val == GrabSuccess)
689 gdk_xgrab_window = window_private;
695 *--------------------------------------------------------------
698 * Releases any pointer grab
706 *--------------------------------------------------------------
710 gdk_pointer_ungrab (guint32 time)
712 if (gdk_input_vtable.ungrab_pointer)
713 gdk_input_vtable.ungrab_pointer (time);
715 XUngrabPointer (gdk_display, time);
716 gdk_xgrab_window = NULL;
720 *--------------------------------------------------------------
721 * gdk_pointer_is_grabbed
723 * Tell wether there is an active x pointer grab in effect
731 *--------------------------------------------------------------
735 gdk_pointer_is_grabbed (void)
737 return gdk_xgrab_window != NULL;
741 *--------------------------------------------------------------
744 * Grabs the keyboard to a specific window
747 * "window" is the window which will receive the grab
748 * "owner_events" specifies whether events will be reported as is,
749 * or relative to "window"
750 * "time" specifies the time
755 * requires a corresponding call to gdk_keyboard_ungrab
757 *--------------------------------------------------------------
761 gdk_keyboard_grab (GdkWindow * window,
765 GdkWindowPrivate *window_private;
768 g_return_val_if_fail (window != NULL, 0);
770 window_private = (GdkWindowPrivate*) window;
771 xwindow = window_private->xwindow;
773 if (!window_private->destroyed)
774 return XGrabKeyboard (window_private->xdisplay,
777 GrabModeAsync, GrabModeAsync,
780 return AlreadyGrabbed;
784 *--------------------------------------------------------------
785 * gdk_keyboard_ungrab
787 * Releases any keyboard grab
795 *--------------------------------------------------------------
799 gdk_keyboard_ungrab (guint32 time)
801 XUngrabKeyboard (gdk_display, time);
805 *--------------------------------------------------------------
808 * Return the width of the screen.
816 *--------------------------------------------------------------
820 gdk_screen_width (void)
824 return_val = DisplayWidth (gdk_display, gdk_screen);
830 *--------------------------------------------------------------
833 * Return the height of the screen.
841 *--------------------------------------------------------------
845 gdk_screen_height (void)
849 return_val = DisplayHeight (gdk_display, gdk_screen);
855 *--------------------------------------------------------------
856 * gdk_screen_width_mm
858 * Return the width of the screen in millimeters.
866 *--------------------------------------------------------------
870 gdk_screen_width_mm (void)
874 return_val = DisplayWidthMM (gdk_display, gdk_screen);
880 *--------------------------------------------------------------
883 * Return the height of the screen in millimeters.
891 *--------------------------------------------------------------
895 gdk_screen_height_mm (void)
899 return_val = DisplayHeightMM (gdk_display, gdk_screen);
905 *--------------------------------------------------------------
906 * gdk_set_sm_client_id
908 * Set the SM_CLIENT_ID property on the WM_CLIENT_LEADER window
909 * so that the window manager can save our state using the
910 * X11R6 ICCCM session management protocol. A NULL value should
911 * be set following disconnection from the session manager to
912 * remove the SM_CLIENT_ID property.
916 * "sm_client_id" specifies the client id assigned to us by the
917 * session manager or NULL to remove the property.
923 *--------------------------------------------------------------
927 gdk_set_sm_client_id (const gchar* sm_client_id)
929 if (sm_client_id && strcmp (sm_client_id, ""))
931 XChangeProperty (gdk_display, gdk_leader_window,
932 gdk_atom_intern ("SM_CLIENT_ID", FALSE),
933 XA_STRING, 8, PropModeReplace,
934 sm_client_id, strlen(sm_client_id));
937 XDeleteProperty (gdk_display, gdk_leader_window,
938 gdk_atom_intern ("SM_CLIENT_ID", FALSE));
942 gdk_key_repeat_disable (void)
944 XAutoRepeatOff (gdk_display);
948 gdk_key_repeat_restore (void)
951 XAutoRepeatOn (gdk_display);
953 XAutoRepeatOff (gdk_display);
960 XBell(gdk_display, 100);
964 *--------------------------------------------------------------
967 * This is the "atexit" function that makes sure the
968 * library gets a chance to cleanup.
975 * The library is un-initialized and the program exits.
977 *--------------------------------------------------------------
983 static gboolean in_gdk_exit_func = FALSE;
985 /* This is to avoid an infinite loop if a program segfaults in
986 an atexit() handler (and yes, it does happen, especially if a program
987 has trounced over memory too badly for even g_message to work) */
988 if (in_gdk_exit_func == TRUE)
990 in_gdk_exit_func = TRUE;
1002 gdk_key_repeat_restore ();
1004 XCloseDisplay (gdk_display);
1005 gdk_initialized = 0;
1010 *--------------------------------------------------------------
1013 * The X error handling routine.
1016 * "display" is the X display the error orignated from.
1017 * "error" is the XErrorEvent that we are handling.
1020 * Either we were expecting some sort of error to occur,
1021 * in which case we set the "gdk_error_code" flag, or this
1022 * error was unexpected, in which case we will print an
1023 * error message and exit. (Since trying to continue will
1024 * most likely simply lead to more errors).
1028 *--------------------------------------------------------------
1032 gdk_x_error (Display *display,
1037 if (gdk_error_warnings)
1039 XGetErrorText (display, error->error_code, buf, 63);
1040 g_error ("%s\n serial %ld error_code %d request_code %d minor_code %d\n",
1044 error->request_code,
1048 gdk_error_code = -1;
1053 *--------------------------------------------------------------
1056 * The X I/O error handling routine.
1059 * "display" is the X display the error orignated from.
1062 * An X I/O error basically means we lost our connection
1063 * to the X server. There is not much we can do to
1064 * continue, so simply print an error message and exit.
1068 *--------------------------------------------------------------
1072 gdk_x_io_error (Display *display)
1074 g_error ("an x io error occurred");
1079 gdk_get_display (void)
1081 return (gchar *)XDisplayName (gdk_display_name);
1084 /*************************************************************
1085 * gdk_error_trap_push:
1086 * Push an error trap. X errors will be trapped until
1087 * the corresponding gdk_error_pop(), which will return
1088 * the error code, if any.
1092 *************************************************************/
1095 gdk_error_trap_push (void)
1100 if (gdk_error_trap_free_list)
1102 node = gdk_error_trap_free_list;
1103 gdk_error_trap_free_list = gdk_error_trap_free_list->next;
1107 node = g_slist_alloc();
1108 node->data = g_new (GdkErrorTrap, 1);
1111 node->next = gdk_error_traps;
1112 gdk_error_traps = node;
1115 trap->error_code = gdk_error_code;
1116 trap->error_warnings = gdk_error_warnings;
1119 gdk_error_warnings = 0;
1122 /*************************************************************
1123 * gdk_error_trap_pop:
1124 * Pop an error trap added with gdk_error_push()
1128 * 0, if no error occured, otherwise the error code.
1129 *************************************************************/
1132 gdk_error_trap_pop (void)
1138 g_return_val_if_fail (gdk_error_traps != NULL, 0);
1140 node = gdk_error_traps;
1141 gdk_error_traps = gdk_error_traps->next;
1143 node->next = gdk_error_trap_free_list;
1144 gdk_error_trap_free_list = node;
1146 result = gdk_error_code;
1149 gdk_error_code = trap->error_code;
1150 gdk_error_warnings = trap->error_warnings;
1156 gdk_send_xevent (Window window, gboolean propagate, glong event_mask,
1160 gint old_warnings = gdk_error_warnings;
1164 gdk_error_warnings = 0;
1165 result = XSendEvent (gdk_display, window, propagate, event_mask, event_send);
1166 XSync (gdk_display, False);
1167 gdk_error_warnings = old_warnings;
1169 return result && (gdk_error_code != -1);
1172 #ifndef HAVE_XCONVERTCASE
1173 /* compatibility function from X11R6.3, since XConvertCase is not
1174 * supplied by X11R5.
1177 gdkx_XConvertCase (KeySym symbol,
1181 register KeySym sym = symbol;
1183 g_return_if_fail (lower != NULL);
1184 g_return_if_fail (upper != NULL);
1191 #if defined (GDK_A) && defined (GDK_Ooblique)
1192 case 0: /* Latin 1 */
1193 if ((sym >= GDK_A) && (sym <= GDK_Z))
1194 *lower += (GDK_a - GDK_A);
1195 else if ((sym >= GDK_a) && (sym <= GDK_z))
1196 *upper -= (GDK_a - GDK_A);
1197 else if ((sym >= GDK_Agrave) && (sym <= GDK_Odiaeresis))
1198 *lower += (GDK_agrave - GDK_Agrave);
1199 else if ((sym >= GDK_agrave) && (sym <= GDK_odiaeresis))
1200 *upper -= (GDK_agrave - GDK_Agrave);
1201 else if ((sym >= GDK_Ooblique) && (sym <= GDK_Thorn))
1202 *lower += (GDK_oslash - GDK_Ooblique);
1203 else if ((sym >= GDK_oslash) && (sym <= GDK_thorn))
1204 *upper -= (GDK_oslash - GDK_Ooblique);
1208 #if defined (GDK_Aogonek) && defined (GDK_tcedilla)
1209 case 1: /* Latin 2 */
1210 /* Assume the KeySym is a legal value (ignore discontinuities) */
1211 if (sym == GDK_Aogonek)
1212 *lower = GDK_aogonek;
1213 else if (sym >= GDK_Lstroke && sym <= GDK_Sacute)
1214 *lower += (GDK_lstroke - GDK_Lstroke);
1215 else if (sym >= GDK_Scaron && sym <= GDK_Zacute)
1216 *lower += (GDK_scaron - GDK_Scaron);
1217 else if (sym >= GDK_Zcaron && sym <= GDK_Zabovedot)
1218 *lower += (GDK_zcaron - GDK_Zcaron);
1219 else if (sym == GDK_aogonek)
1220 *upper = GDK_Aogonek;
1221 else if (sym >= GDK_lstroke && sym <= GDK_sacute)
1222 *upper -= (GDK_lstroke - GDK_Lstroke);
1223 else if (sym >= GDK_scaron && sym <= GDK_zacute)
1224 *upper -= (GDK_scaron - GDK_Scaron);
1225 else if (sym >= GDK_zcaron && sym <= GDK_zabovedot)
1226 *upper -= (GDK_zcaron - GDK_Zcaron);
1227 else if (sym >= GDK_Racute && sym <= GDK_Tcedilla)
1228 *lower += (GDK_racute - GDK_Racute);
1229 else if (sym >= GDK_racute && sym <= GDK_tcedilla)
1230 *upper -= (GDK_racute - GDK_Racute);
1234 #if defined (GDK_Hstroke) && defined (GDK_Cabovedot)
1235 case 2: /* Latin 3 */
1236 /* Assume the KeySym is a legal value (ignore discontinuities) */
1237 if (sym >= GDK_Hstroke && sym <= GDK_Hcircumflex)
1238 *lower += (GDK_hstroke - GDK_Hstroke);
1239 else if (sym >= GDK_Gbreve && sym <= GDK_Jcircumflex)
1240 *lower += (GDK_gbreve - GDK_Gbreve);
1241 else if (sym >= GDK_hstroke && sym <= GDK_hcircumflex)
1242 *upper -= (GDK_hstroke - GDK_Hstroke);
1243 else if (sym >= GDK_gbreve && sym <= GDK_jcircumflex)
1244 *upper -= (GDK_gbreve - GDK_Gbreve);
1245 else if (sym >= GDK_Cabovedot && sym <= GDK_Scircumflex)
1246 *lower += (GDK_cabovedot - GDK_Cabovedot);
1247 else if (sym >= GDK_cabovedot && sym <= GDK_scircumflex)
1248 *upper -= (GDK_cabovedot - GDK_Cabovedot);
1252 #if defined (GDK_Rcedilla) && defined (GDK_Amacron)
1253 case 3: /* Latin 4 */
1254 /* Assume the KeySym is a legal value (ignore discontinuities) */
1255 if (sym >= GDK_Rcedilla && sym <= GDK_Tslash)
1256 *lower += (GDK_rcedilla - GDK_Rcedilla);
1257 else if (sym >= GDK_rcedilla && sym <= GDK_tslash)
1258 *upper -= (GDK_rcedilla - GDK_Rcedilla);
1259 else if (sym == GDK_ENG)
1261 else if (sym == GDK_eng)
1263 else if (sym >= GDK_Amacron && sym <= GDK_Umacron)
1264 *lower += (GDK_amacron - GDK_Amacron);
1265 else if (sym >= GDK_amacron && sym <= GDK_umacron)
1266 *upper -= (GDK_amacron - GDK_Amacron);
1270 #if defined (GDK_Serbian_DJE) && defined (GDK_Cyrillic_yu)
1271 case 6: /* Cyrillic */
1272 /* Assume the KeySym is a legal value (ignore discontinuities) */
1273 if (sym >= GDK_Serbian_DJE && sym <= GDK_Serbian_DZE)
1274 *lower -= (GDK_Serbian_DJE - GDK_Serbian_dje);
1275 else if (sym >= GDK_Serbian_dje && sym <= GDK_Serbian_dze)
1276 *upper += (GDK_Serbian_DJE - GDK_Serbian_dje);
1277 else if (sym >= GDK_Cyrillic_YU && sym <= GDK_Cyrillic_HARDSIGN)
1278 *lower -= (GDK_Cyrillic_YU - GDK_Cyrillic_yu);
1279 else if (sym >= GDK_Cyrillic_yu && sym <= GDK_Cyrillic_hardsign)
1280 *upper += (GDK_Cyrillic_YU - GDK_Cyrillic_yu);
1282 #endif /* CYRILLIC */
1284 #if defined (GDK_Greek_ALPHAaccent) && defined (GDK_Greek_finalsmallsigma)
1286 /* Assume the KeySym is a legal value (ignore discontinuities) */
1287 if (sym >= GDK_Greek_ALPHAaccent && sym <= GDK_Greek_OMEGAaccent)
1288 *lower += (GDK_Greek_alphaaccent - GDK_Greek_ALPHAaccent);
1289 else if (sym >= GDK_Greek_alphaaccent && sym <= GDK_Greek_omegaaccent &&
1290 sym != GDK_Greek_iotaaccentdieresis &&
1291 sym != GDK_Greek_upsilonaccentdieresis)
1292 *upper -= (GDK_Greek_alphaaccent - GDK_Greek_ALPHAaccent);
1293 else if (sym >= GDK_Greek_ALPHA && sym <= GDK_Greek_OMEGA)
1294 *lower += (GDK_Greek_alpha - GDK_Greek_ALPHA);
1295 else if (sym >= GDK_Greek_alpha && sym <= GDK_Greek_omega &&
1296 sym != GDK_Greek_finalsmallsigma)
1297 *upper -= (GDK_Greek_alpha - GDK_Greek_ALPHA);
1305 gdk_keyval_name (guint keyval)
1307 return XKeysymToString (keyval);
1311 gdk_keyval_from_name (const gchar *keyval_name)
1313 g_return_val_if_fail (keyval_name != NULL, 0);
1315 return XStringToKeysym (keyval_name);
1319 gdk_keyval_to_upper (guint keyval)
1323 KeySym lower_val = 0;
1324 KeySym upper_val = 0;
1326 XConvertCase (keyval, &lower_val, &upper_val);
1333 gdk_keyval_to_lower (guint keyval)
1337 KeySym lower_val = 0;
1338 KeySym upper_val = 0;
1340 XConvertCase (keyval, &lower_val, &upper_val);
1347 gdk_keyval_is_upper (guint keyval)
1351 KeySym lower_val = 0;
1352 KeySym upper_val = 0;
1354 XConvertCase (keyval, &lower_val, &upper_val);
1355 return upper_val == keyval;
1361 gdk_keyval_is_lower (guint keyval)
1365 KeySym lower_val = 0;
1366 KeySym upper_val = 0;
1368 XConvertCase (keyval, &lower_val, &upper_val);
1369 return lower_val == keyval;
1375 gdk_threads_enter ()
1377 GDK_THREADS_ENTER ();
1381 gdk_threads_leave ()
1383 GDK_THREADS_LEAVE ();