/[rdesktop]/sourceforge.net/branches/seamlessrdp-branch/rdesktop/xwin.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/branches/seamlessrdp-branch/rdesktop/xwin.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1151 by ossman_, Fri Mar 17 08:52:29 2006 UTC revision 1166 by ossman_, Mon Mar 20 12:36:14 2006 UTC
# Line 54  typedef struct _seamless_window Line 54  typedef struct _seamless_window
54  {  {
55          Window wnd;          Window wnd;
56          unsigned long id;          unsigned long id;
57          unsigned long parent;          unsigned long behind;
58          int xoffset, yoffset;          int xoffset, yoffset;
59          int width, height;          int width, height;
60          int state;              /* normal/minimized/maximized. */          int state;              /* normal/minimized/maximized. */
61          unsigned int desktop;          unsigned int desktop;
62            struct timeval *position_timer;
63          struct _seamless_window *next;          struct _seamless_window *next;
64  } seamless_window;  } seamless_window;
65  static seamless_window *g_seamless_windows = NULL;  static seamless_window *g_seamless_windows = NULL;
66    static unsigned long g_seamless_focused = 0;
67  static BOOL g_seamless_started = False; /* Server end is up and running */  static BOOL g_seamless_started = False; /* Server end is up and running */
68  static BOOL g_seamless_active = False;  /* We are currently in seamless mode */  static BOOL g_seamless_active = False;  /* We are currently in seamless mode */
69  extern BOOL g_seamless_rdp;  extern BOOL g_seamless_rdp;
# Line 323  seamless_all_to_desktop(Window wnd, unsi Line 325  seamless_all_to_desktop(Window wnd, unsi
325  }  }
326    
327    
328    /* Send our position */
329    static void
330    seamless_update_position(seamless_window * sw)
331    {
332            XWindowAttributes wa;
333            int x, y;
334            Window child_return;
335    
336            XGetWindowAttributes(g_display, sw->wnd, &wa);
337            XTranslateCoordinates(g_display, sw->wnd, wa.root,
338                                  -wa.border_width, -wa.border_width, &x, &y, &child_return);
339    
340            seamless_send_position(sw->id, x, y, wa.width, wa.height, 0);
341            sw->xoffset = x;
342            sw->yoffset = y;
343            sw->width = wa.width;
344            sw->height = wa.height;
345    }
346    
347    
348    /* Check if it's time to send our position */
349    static void
350    seamless_check_timers()
351    {
352            seamless_window *sw;
353            struct timeval now;
354    
355            gettimeofday(&now, NULL);
356            for (sw = g_seamless_windows; sw; sw = sw->next)
357            {
358                    if (timerisset(sw->position_timer) && timercmp(sw->position_timer, &now, <))
359                    {
360                            timerclear(sw->position_timer);
361                            seamless_update_position(sw);
362                    }
363            }
364    }
365    
366    
367    static void
368    seamless_restack_window(seamless_window * sw, unsigned long behind)
369    {
370            seamless_window *sw_above;
371    
372            /* Remove window from stack */
373            for (sw_above = g_seamless_windows; sw_above; sw_above = sw_above->next)
374            {
375                    if (sw_above->behind == sw->id)
376                            break;
377            }
378    
379            if (sw_above)
380                    sw_above->behind = sw->behind;
381    
382            /* And then add it at the new position */
383    
384            for (sw_above = g_seamless_windows; sw_above; sw_above = sw_above->next)
385            {
386                    if (sw_above->behind == behind)
387                            break;
388            }
389    
390            if (sw_above)
391                    sw_above->behind = sw->id;
392    
393            sw->behind = behind;
394    }
395    
396    
397  static void  static void
398  mwm_hide_decorations(Window wnd)  mwm_hide_decorations(Window wnd)
399  {  {
# Line 1774  ui_seamless_handle_restack(seamless_wind Line 1845  ui_seamless_handle_restack(seamless_wind
1845                          break;                          break;
1846          }          }
1847    
1848            if (!sw_below && !sw->behind)
1849                    return;
1850            if (sw_below && (sw_below->id == sw->behind))
1851                    return;
1852    
1853          if (sw_below)          if (sw_below)
1854            {
1855                  seamless_send_zchange(sw->id, sw_below->id, 0);                  seamless_send_zchange(sw->id, sw_below->id, 0);
1856                    seamless_restack_window(sw, sw_below->id);
1857            }
1858          else          else
1859            {
1860                  seamless_send_zchange(sw->id, 0, 0);                  seamless_send_zchange(sw->id, 0, 0);
1861                    seamless_restack_window(sw, 0);
1862            }
1863  }  }
1864    
1865  /* Process events in Xlib queue  /* Process events in Xlib queue
# Line 1912  xwin_process_events(void) Line 1994  xwin_process_events(void)
1994                                  if (g_grab_keyboard && g_mouse_in_wnd)                                  if (g_grab_keyboard && g_mouse_in_wnd)
1995                                          XGrabKeyboard(g_display, g_wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1996                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
1997    
1998                                    sw = seamless_get_window_by_wnd(xevent.xfocus.window);
1999                                    if (!sw)
2000                                            break;
2001    
2002                                    if (sw->id != g_seamless_focused)
2003                                    {
2004                                            seamless_send_focus(sw->id, 0);
2005                                            g_seamless_focused = sw->id;
2006                                    }
2007                                  break;                                  break;
2008    
2009                          case FocusOut:                          case FocusOut:
# Line 2032  xwin_process_events(void) Line 2124  xwin_process_events(void)
2124                                          rdp_send_client_window_status(0);                                          rdp_send_client_window_status(0);
2125                                  break;                                  break;
2126                          case ConfigureNotify:                          case ConfigureNotify:
2127                                  /* seamless */                                  if (!g_seamless_active)
2128                                            break;
2129    
2130                                  sw = seamless_get_window_by_wnd(xevent.xconfigure.window);                                  sw = seamless_get_window_by_wnd(xevent.xconfigure.window);
2131                                  if (!sw)                                  if (!sw)
2132                                          break;                                  {
2133                                            error("ConfigureNotify for unknown window 0x%lx\n",
2134                                                  xevent.xconfigure.window);
2135                                    }
2136    
2137                                    gettimeofday(sw->position_timer, NULL);
2138                                    if (sw->position_timer->tv_usec + SEAMLESSRDP_POSITION_TIMER >=
2139                                        1000000)
2140                                    {
2141                                            sw->position_timer->tv_usec +=
2142                                                    SEAMLESSRDP_POSITION_TIMER - 1000000;
2143                                            sw->position_timer->tv_sec += 1;
2144                                    }
2145                                    else
2146                                    {
2147                                            sw->position_timer->tv_usec += SEAMLESSRDP_POSITION_TIMER;
2148                                    }
2149    
2150                                  ui_seamless_handle_restack(sw);                                  ui_seamless_handle_restack(sw);
2151                                    break;
2152                  }                  }
2153          }          }
2154          /* Keep going */          /* Keep going */
# Line 2061  ui_select(int rdp_socket) Line 2172  ui_select(int rdp_socket)
2172                          /* User quit */                          /* User quit */
2173                          return 0;                          return 0;
2174    
2175                    if (g_seamless_active)
2176                            seamless_check_timers();
2177    
2178                  FD_ZERO(&rfds);                  FD_ZERO(&rfds);
2179                  FD_ZERO(&wfds);                  FD_ZERO(&wfds);
2180                  FD_SET(rdp_socket, &rfds);                  FD_SET(rdp_socket, &rfds);
# Line 2080  ui_select(int rdp_socket) Line 2194  ui_select(int rdp_socket)
2194    
2195                  /* add redirection handles */                  /* add redirection handles */
2196                  rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);                  rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);
2197                    seamless_select_timeout(&tv);
2198    
2199                  n++;                  n++;
2200    
# Line 3140  ui_seamless_create_window(unsigned long Line 3255  ui_seamless_create_window(unsigned long
3255                  XFree(sizehints);                  XFree(sizehints);
3256          }          }
3257    
3258            /* Handle popups without parents through some ewm hints */
3259            if (parent == 0xFFFFFFFF)
3260                    ewmh_set_window_popup(wnd);
3261          /* Set WM_TRANSIENT_FOR, if necessary */          /* Set WM_TRANSIENT_FOR, if necessary */
3262          if ((parent != 0x00000000) && (parent != 0xFFFFFFFF))          else if (parent != 0x00000000)
3263          {          {
3264                  sw_parent = seamless_get_window_by_id(parent);                  sw_parent = seamless_get_window_by_id(parent);
3265                  if (sw_parent)                  if (sw_parent)
# Line 3163  ui_seamless_create_window(unsigned long Line 3281  ui_seamless_create_window(unsigned long
3281             serverside, instead of terminating rdesktop */             serverside, instead of terminating rdesktop */
3282          XSetWMProtocols(g_display, wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, wnd, &g_kill_atom, 1);
3283    
3284          sw = malloc(sizeof(seamless_window));          sw = xmalloc(sizeof(seamless_window));
3285          sw->wnd = wnd;          sw->wnd = wnd;
3286          sw->id = id;          sw->id = id;
3287          sw->parent = parent;          sw->behind = 0;
3288          sw->xoffset = 0;          sw->xoffset = 0;
3289          sw->yoffset = 0;          sw->yoffset = 0;
3290          sw->width = 0;          sw->width = 0;
3291          sw->height = 0;          sw->height = 0;
3292          sw->state = SEAMLESSRDP_NOTYETMAPPED;          sw->state = SEAMLESSRDP_NOTYETMAPPED;
3293          sw->desktop = 0;          sw->desktop = 0;
3294            sw->position_timer = xmalloc(sizeof(struct timeval));
3295            timerclear(sw->position_timer);
3296          sw->next = g_seamless_windows;          sw->next = g_seamless_windows;
3297          g_seamless_windows = sw;          g_seamless_windows = sw;
3298  }  }
# Line 3217  ui_seamless_move_window(unsigned long id Line 3337  ui_seamless_move_window(unsigned long id
3337                  /* X11 windows must be at least 1x1 */                  /* X11 windows must be at least 1x1 */
3338                  return;                  return;
3339    
3340          /* About MAX and MIN: Windows allows moving a window outside          sw->xoffset = x;
3341             the desktop. This happens, for example, when maximizing an          sw->yoffset = y;
3342             application. In this case, the position is set to something          sw->width = width;
3343             like -4,-4,1288,1032. Many WMs does not allow windows          sw->height = height;
            outside the desktop, however. Therefore, clip the window  
            ourselves. */  
         sw->xoffset = MAX(0, x);  
         sw->yoffset = MAX(0, y);  
         sw->width = MIN(MIN(width, width + x), g_width - sw->xoffset);  
         sw->height = MIN(MIN(height, height + y), g_height - sw->yoffset);  
3344    
3345          /* If we move the window in a maximized state, then KDE won't          /* If we move the window in a maximized state, then KDE won't
3346             accept restoration */             accept restoration */
# Line 3278  ui_seamless_restack_window(unsigned long Line 3392  ui_seamless_restack_window(unsigned long
3392          {          {
3393                  XRaiseWindow(g_display, sw->wnd);                  XRaiseWindow(g_display, sw->wnd);
3394          }          }
3395    
3396            seamless_restack_window(sw, behind);
3397  }  }
3398    
3399  void  void
# Line 3347  ui_seamless_setstate(unsigned long id, u Line 3463  ui_seamless_setstate(unsigned long id, u
3463                          break;                          break;
3464          }          }
3465    
         /* Handle popups without parents through some ewm hints */  
         if ((sw->state == SEAMLESSRDP_NOTYETMAPPED) && (sw->parent == 0xFFFFFFFF))  
                 ewmh_set_window_popup(sw->wnd);  
   
3466          sw->state = state;          sw->state = state;
3467  }  }
3468    
# Line 3368  ui_seamless_syncbegin(unsigned long flag Line 3480  ui_seamless_syncbegin(unsigned long flag
3480                  seamless_remove_window(g_seamless_windows);                  seamless_remove_window(g_seamless_windows);
3481          }          }
3482  }  }
3483    
3484    void
3485    ui_seamless_ack(unsigned int serial)
3486    {
3487    }

Legend:
Removed from v.1151  
changed lines
  Added in v.1166

  ViewVC Help
Powered by ViewVC 1.1.26