/[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 1094 by astrand, Fri Mar 10 10:40:50 2006 UTC revision 1144 by ossman_, Thu Mar 16 10:14:18 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;
58          int xoffset, yoffset;          int xoffset, yoffset;
59          int width, height;          int width, height;
60            int state;              /* normal/minimized/maximized. */
61            unsigned int desktop;
62          struct _seamless_window *next;          struct _seamless_window *next;
63  } seamless_window;  } seamless_window;
64  static seamless_window *g_seamless_windows = NULL;  static seamless_window *g_seamless_windows = NULL;
# Line 83  static XModifierKeymap *g_mod_map; Line 86  static XModifierKeymap *g_mod_map;
86  static Cursor g_current_cursor;  static Cursor g_current_cursor;
87  static HCURSOR g_null_cursor = NULL;  static HCURSOR g_null_cursor = NULL;
88  static Atom g_protocol_atom, g_kill_atom;  static Atom g_protocol_atom, g_kill_atom;
89    extern Atom g_net_wm_state_atom;
90    extern Atom g_net_wm_desktop_atom;
91  static BOOL g_focused;  static BOOL g_focused;
92  static BOOL g_mouse_in_wnd;  static BOOL g_mouse_in_wnd;
93  /* Indicates that:  /* Indicates that:
# Line 298  seamless_remove_window(seamless_window * Line 303  seamless_remove_window(seamless_window *
303  }  }
304    
305    
306    /* Move all windows except wnd to new desktop */
307    static void
308    seamless_all_to_desktop(Window wnd, unsigned int desktop)
309    {
310            seamless_window *sw;
311            for (sw = g_seamless_windows; sw; sw = sw->next)
312            {
313                    if (sw->wnd == wnd)
314                            continue;
315                    if (sw->desktop != desktop)
316                    {
317                            ewmh_move_to_desktop(sw->wnd, desktop);
318                            sw->desktop = desktop;
319                    }
320            }
321    }
322    
323    
324  static void  static void
325  mwm_hide_decorations(Window wnd)  mwm_hide_decorations(Window wnd)
326  {  {
# Line 1396  ui_init(void) Line 1419  ui_init(void)
1419                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);
1420    
1421          xclip_init();          xclip_init();
1422            ewmh_init();
1423          if (g_seamless_rdp)          if (g_seamless_rdp)
1424                  seamless_init();                  seamless_init();
1425    
# Line 1903  xwin_process_events(void) Line 1927  xwin_process_events(void)
1927                                                            xevent.xexpose.width,                                                            xevent.xexpose.width,
1928                                                            xevent.xexpose.height, xevent.xexpose.x,                                                            xevent.xexpose.height, xevent.xexpose.x,
1929                                                            xevent.xexpose.y);                                                            xevent.xexpose.y);
1930                                            else
1931                                            {
1932                                                    error("Expose for unknown window 0x%lx\n",
1933                                                          xevent.xexpose.window);
1934                                            }
1935                                  }                                  }
1936    
1937                                  break;                                  break;
# Line 1933  xwin_process_events(void) Line 1962  xwin_process_events(void)
1962                                  break;                                  break;
1963                          case PropertyNotify:                          case PropertyNotify:
1964                                  xclip_handle_PropertyNotify(&xevent.xproperty);                                  xclip_handle_PropertyNotify(&xevent.xproperty);
1965                                    if (xevent.xproperty.window == g_wnd)
1966                                            break;
1967                                    if (xevent.xproperty.window == DefaultRootWindow(g_display))
1968                                            break;
1969    
1970                                    /* seamless */
1971                                    sw = seamless_get_window_by_wnd(xevent.xproperty.window);
1972                                    if (!sw)
1973                                            break;
1974    
1975                                    if ((xevent.xproperty.atom == g_net_wm_state_atom)
1976                                        && (xevent.xproperty.state == PropertyNewValue))
1977                                    {
1978                                            sw->state = ewmh_get_window_state(sw->wnd);
1979                                            seamless_send_state(sw->id, sw->state, 0);
1980                                    }
1981    
1982                                    if ((xevent.xproperty.atom == g_net_wm_desktop_atom)
1983                                        && (xevent.xproperty.state == PropertyNewValue))
1984                                    {
1985                                            sw->desktop = ewmh_get_window_desktop(sw->wnd);
1986                                            seamless_all_to_desktop(sw->wnd, sw->desktop);
1987                                    }
1988    
1989                                  break;                                  break;
1990                          case MapNotify:                          case MapNotify:
1991                                  if (!g_seamless_rdp)                                  if (!g_seamless_rdp)
# Line 2987  ui_seamless_toggle() Line 3040  ui_seamless_toggle()
3040  }  }
3041    
3042  void  void
3043  ui_seamless_create_window(unsigned long id, unsigned long flags)  ui_seamless_create_window(unsigned long id, unsigned long parent, unsigned long flags)
3044  {  {
3045          Window wnd;          Window wnd;
3046          XSetWindowAttributes attribs;          XSetWindowAttributes attribs;
3047          XClassHint *classhints;          XClassHint *classhints;
3048            XSizeHints *sizehints;
3049          long input_mask;          long input_mask;
3050          seamless_window *sw;          seamless_window *sw, *sw_parent;
3051    
3052          get_window_attribs(&attribs);          /* Ignore CREATEs for existing windows */
3053            sw = seamless_get_window_by_id(id);
3054            if (sw)
3055                    return;
3056    
3057            get_window_attribs(&attribs);
3058          attribs.override_redirect = False;          attribs.override_redirect = False;
3059    
3060          /* FIXME: Do not assume that -1, -1 is outside screen Consider          wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), -1, -1, 1, 1, 0, g_depth,
            wait with showing the window until STATE and others have  
            been recieved. */  
         wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), -1, -1, 1, 1, 0, 0,  
3061                              InputOutput, g_visual,                              InputOutput, g_visual,
3062                              CWBackPixel | CWBackingStore | CWOverrideRedirect | CWColormap |                              CWBackPixel | CWBackingStore | CWOverrideRedirect | CWColormap |
3063                              CWBorderPixel, &attribs);                              CWBorderPixel, &attribs);
3064    
3065          XStoreName(g_display, wnd, "rdesktop-seamless");          XStoreName(g_display, wnd, "SeamlessRDP");
3066            ewmh_set_wm_name(wnd, "SeamlessRDP");
3067    
3068          mwm_hide_decorations(wnd);          mwm_hide_decorations(wnd);
3069    
3070          classhints = XAllocClassHint();          classhints = XAllocClassHint();
3071          if (classhints != NULL)          if (classhints != NULL)
3072          {          {
3073                  classhints->res_name = classhints->res_class = "rdesktop";                  classhints->res_name = "rdesktop";
3074                    classhints->res_class = "SeamlessRDP";
3075                  XSetClassHint(g_display, wnd, classhints);                  XSetClassHint(g_display, wnd, classhints);
3076                  XFree(classhints);                  XFree(classhints);
3077          }          }
3078    
3079            /* WM_NORMAL_HINTS */
3080            sizehints = XAllocSizeHints();
3081            if (sizehints != NULL)
3082            {
3083                    sizehints->flags = USPosition;
3084                    XSetWMNormalHints(g_display, wnd, sizehints);
3085                    XFree(sizehints);
3086            }
3087    
3088            /* Set WM_TRANSIENT_FOR, if necessary */
3089            if ((parent != 0x00000000) && (parent != 0xFFFFFFFF))
3090            {
3091                    sw_parent = seamless_get_window_by_id(parent);
3092                    if (sw_parent)
3093                            XSetTransientForHint(g_display, wnd, sw_parent->wnd);
3094                    else
3095                            warning("ui_seamless_create_window: No parent window 0x%lx\n", parent);
3096            }
3097    
3098    
3099          /* FIXME: Support for Input Context:s */          /* FIXME: Support for Input Context:s */
3100    
3101          get_input_mask(&input_mask);          get_input_mask(&input_mask);
3102            input_mask |= PropertyChangeMask;
3103    
3104          XSelectInput(g_display, wnd, input_mask);          XSelectInput(g_display, wnd, input_mask);
3105    
         XMapWindow(g_display, wnd);  
   
3106          /* handle the WM_DELETE_WINDOW protocol. FIXME: When killing a          /* handle the WM_DELETE_WINDOW protocol. FIXME: When killing a
3107             seamless window, we could try to close the window on the             seamless window, we could try to close the window on the
3108             serverside, instead of terminating rdesktop */             serverside, instead of terminating rdesktop */
# Line 3035  ui_seamless_create_window(unsigned long Line 3111  ui_seamless_create_window(unsigned long
3111          sw = malloc(sizeof(seamless_window));          sw = malloc(sizeof(seamless_window));
3112          sw->wnd = wnd;          sw->wnd = wnd;
3113          sw->id = id;          sw->id = id;
3114            sw->parent = parent;
3115          sw->xoffset = 0;          sw->xoffset = 0;
3116          sw->yoffset = 0;          sw->yoffset = 0;
3117          sw->width = 0;          sw->width = 0;
3118          sw->height = 0;          sw->height = 0;
3119            sw->state = SEAMLESSRDP_NOTYETMAPPED;
3120            sw->desktop = 0;
3121          sw->next = g_seamless_windows;          sw->next = g_seamless_windows;
3122          g_seamless_windows = sw;          g_seamless_windows = sw;
3123  }  }
# Line 3048  void Line 3127  void
3127  ui_seamless_destroy_window(unsigned long id, unsigned long flags)  ui_seamless_destroy_window(unsigned long id, unsigned long flags)
3128  {  {
3129          seamless_window *sw;          seamless_window *sw;
         sw = seamless_get_window_by_id(id);  
3130    
3131            sw = seamless_get_window_by_id(id);
3132          if (!sw)          if (!sw)
3133          {          {
3134                  warning("ui_seamless_destroy_window: No information for window 0x%lx\n", id);                  warning("ui_seamless_destroy_window: No information for window 0x%lx\n", id);
# Line 3067  ui_seamless_move_window(unsigned long id Line 3146  ui_seamless_move_window(unsigned long id
3146          seamless_window *sw;          seamless_window *sw;
3147    
3148          sw = seamless_get_window_by_id(id);          sw = seamless_get_window_by_id(id);
   
3149          if (!sw)          if (!sw)
3150          {          {
3151                  warning("ui_seamless_move_window: No information for window 0x%lx\n", id);                  warning("ui_seamless_move_window: No information for window 0x%lx\n", id);
# Line 3089  ui_seamless_move_window(unsigned long id Line 3167  ui_seamless_move_window(unsigned long id
3167          sw->width = MIN(MIN(width, width + x), g_width - sw->xoffset);          sw->width = MIN(MIN(width, width + x), g_width - sw->xoffset);
3168          sw->height = MIN(MIN(height, height + y), g_height - sw->yoffset);          sw->height = MIN(MIN(height, height + y), g_height - sw->yoffset);
3169    
3170            /* If we move the window in a maximized state, then KDE won't
3171               accept restoration */
3172            switch (sw->state)
3173            {
3174                    case SEAMLESSRDP_MINIMIZED:
3175                    case SEAMLESSRDP_MAXIMIZED:
3176                            return;
3177            }
3178    
3179          /* FIXME: Perhaps use ewmh_net_moveresize_window instead */          /* FIXME: Perhaps use ewmh_net_moveresize_window instead */
3180          XMoveResizeWindow(g_display, sw->wnd, sw->xoffset, sw->yoffset, sw->width, sw->height);          XMoveResizeWindow(g_display, sw->wnd, sw->xoffset, sw->yoffset, sw->width, sw->height);
3181  }  }
# Line 3100  ui_seamless_settitle(unsigned long id, c Line 3187  ui_seamless_settitle(unsigned long id, c
3187          seamless_window *sw;          seamless_window *sw;
3188    
3189          sw = seamless_get_window_by_id(id);          sw = seamless_get_window_by_id(id);
3190            if (!sw)
3191            {
3192                    warning("ui_seamless_settitle: No information for window 0x%lx\n", id);
3193                    return;
3194            }
3195    
3196            /* FIXME: Might want to convert the name for non-EWMH WMs */
3197          XStoreName(g_display, sw->wnd, title);          XStoreName(g_display, sw->wnd, title);
3198            ewmh_set_wm_name(sw->wnd, title);
3199  }  }
3200    
3201    
# Line 3111  ui_seamless_setstate(unsigned long id, u Line 3205  ui_seamless_setstate(unsigned long id, u
3205          seamless_window *sw;          seamless_window *sw;
3206    
3207          sw = seamless_get_window_by_id(id);          sw = seamless_get_window_by_id(id);
3208            if (!sw)
3209            {
3210                    warning("ui_seamless_setstate: No information for window 0x%lx\n", id);
3211                    return;
3212            }
3213    
3214          switch (state)          switch (state)
3215          {          {
3216                  case SEAMLESSRDP_NORMAL:                  case SEAMLESSRDP_NORMAL:
3217                  case SEAMLESSRDP_MAXIMIZED:                  case SEAMLESSRDP_MAXIMIZED:
3218                          /* FIXME */                          ewmh_change_state(sw->wnd, state);
3219                            XMapWindow(g_display, sw->wnd);
3220                          break;                          break;
3221                  case SEAMLESSRDP_MINIMIZED:                  case SEAMLESSRDP_MINIMIZED:
3222                          XIconifyWindow(g_display, sw->wnd, DefaultScreen(g_display));                          /* EWMH says: "if an Application asks to toggle _NET_WM_STATE_HIDDEN
3223                               the Window Manager should probably just ignore the request, since
3224                               _NET_WM_STATE_HIDDEN is a function of some other aspect of the window
3225                               such as minimization, rather than an independent state." Besides,
3226                               XIconifyWindow is easier. */
3227                            if (sw->state == SEAMLESSRDP_NOTYETMAPPED)
3228                            {
3229                                    XWMHints *hints;
3230                                    hints = XAllocWMHints();
3231                                    hints->flags = StateHint;
3232                                    hints->initial_state = IconicState;
3233                                    XSetWMHints(g_display, sw->wnd, hints);
3234                                    XFree(hints);
3235                                    XMapWindow(g_display, sw->wnd);
3236                            }
3237                            else
3238                                    XIconifyWindow(g_display, sw->wnd, DefaultScreen(g_display));
3239                          break;                          break;
3240                  default:                  default:
3241                          warning("SeamlessRDP: Invalid state %d\n", state);                          warning("SeamlessRDP: Invalid state %d\n", state);
3242                          break;                          break;
3243          }          }
3244    
3245            /* Handle popups without parents through some ewm hints */
3246            if ((sw->state == SEAMLESSRDP_NOTYETMAPPED) && (sw->parent == 0xFFFFFFFF))
3247                    ewmh_set_window_popup(sw->wnd);
3248    
3249            sw->state = state;
3250    }
3251    
3252    
3253    void
3254    ui_seamless_syncbegin(unsigned long flags)
3255    {
3256            /* Destroy all seamless windows */
3257            while (g_seamless_windows)
3258            {
3259                    XDestroyWindow(g_display, g_seamless_windows->wnd);
3260                    seamless_remove_window(g_seamless_windows);
3261            }
3262  }  }

Legend:
Removed from v.1094  
changed lines
  Added in v.1144

  ViewVC Help
Powered by ViewVC 1.1.26