Ignore the coding style change commit during git blame
[xserver.git] / hw / xwin / winclipboardinit.c
blobdbce0bc17de41dacf4aa5735f8dfd6049ab20858
1 /*
2 *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
4 *Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 *"Software"), to deal in the Software without restriction, including
7 *without limitation the rights to use, copy, modify, merge, publish,
8 *distribute, sublicense, and/or sell copies of the Software, and to
9 *permit persons to whom the Software is furnished to do so, subject to
10 *the following conditions:
12 *The above copyright notice and this permission notice shall be
13 *included in all copies or substantial portions of the Software.
15 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
19 *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *Except as contained in this notice, the name of Harold L Hunt II
24 *shall not be used in advertising or otherwise to promote the sale, use
25 *or other dealings in this Software without prior written authorization
26 *from Harold L Hunt II.
28 * Authors: Harold L Hunt II
31 #ifdef HAVE_XWIN_CONFIG_H
32 #include <xwin-config.h>
33 #endif
35 #include <unistd.h>
36 #include <pthread.h>
38 #include "win.h"
39 #include "winclipboard/winclipboard.h"
40 #include "windisplay.h"
41 #include "winauth.h"
43 #define WIN_CLIPBOARD_RETRIES 40
44 #define WIN_CLIPBOARD_DELAY 1
47 * Local variables
50 static pthread_t g_ptClipboardProc;
55 static void *
56 winClipboardThreadProc(void *arg)
58 char szDisplay[512];
59 xcb_auth_info_t *auth_info;
60 int clipboardRestarts = 0;
62 while (1)
64 Bool fShutdown;
66 ++clipboardRestarts;
68 /* Setup the display connection string */
70 * NOTE: Always connect to screen 0 since we require that screen
71 * numbers start at 0 and increase without gaps. We only need
72 * to connect to one screen on the display to get events
73 * for all screens on the display. That is why there is only
74 * one clipboard client thread.
76 winGetDisplayName(szDisplay, 0);
78 /* Print the display connection string */
79 ErrorF("winClipboardThreadProc - DISPLAY=%s\n", szDisplay);
81 /* Flag that clipboard client has been launched */
82 g_fClipboardStarted = TRUE;
84 /* Use our generated cookie for authentication */
85 auth_info = winGetXcbAuthInfo();
87 fShutdown = winClipboardProc(szDisplay, auth_info);
89 /* Flag that clipboard client has stopped */
90 g_fClipboardStarted = FALSE;
92 if (fShutdown)
93 break;
95 /* checking if we need to restart */
96 if (clipboardRestarts >= WIN_CLIPBOARD_RETRIES) {
97 /* terminates clipboard thread but the main server still lives */
98 ErrorF("winClipboardProc - the clipboard thread has restarted %d times and seems to be unstable, disabling clipboard integration\n", clipboardRestarts);
99 g_fClipboard = FALSE;
100 break;
103 sleep(WIN_CLIPBOARD_DELAY);
104 ErrorF("winClipboardProc - trying to restart clipboard thread \n");
107 return NULL;
111 * Initialize the Clipboard module
114 Bool
115 winInitClipboard(void)
117 winDebug("winInitClipboard ()\n");
119 /* Spawn a thread for the Clipboard module */
120 if (pthread_create(&g_ptClipboardProc, NULL, winClipboardThreadProc, NULL)) {
121 /* Bail if thread creation failed */
122 ErrorF("winInitClipboard - pthread_create failed.\n");
123 return FALSE;
126 return TRUE;
129 void
130 winClipboardShutdown(void)
132 /* Close down clipboard resources */
133 if (g_fClipboard && g_fClipboardStarted) {
134 /* Synchronously destroy the clipboard window */
135 winClipboardWindowDestroy();
137 /* Wait for the clipboard thread to exit */
138 pthread_join(g_ptClipboardProc, NULL);
140 g_fClipboardStarted = FALSE;
142 winDebug("winClipboardShutdown - Clipboard thread has exited.\n");