/[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 1142 by ossman_, Thu Mar 16 08:11:29 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            XWMHints *hints;
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 289  seamless_remove_window(seamless_window * Line 294  seamless_remove_window(seamless_window *
294                  if (sw == win)                  if (sw == win)
295                  {                  {
296                          *prevnext = sw->next;                          *prevnext = sw->next;
297                            XFree(sw->hints);
298                          xfree(sw);                          xfree(sw);
299                          return;                          return;
300                  }                  }
# Line 298  seamless_remove_window(seamless_window * Line 304  seamless_remove_window(seamless_window *
304  }  }
305    
306    
307    /* Move all windows except wnd to new desktop */
308    static void
309    seamless_all_to_desktop(Window wnd, unsigned int desktop)
310    {
311            seamless_window *sw;
312            for (sw = g_seamless_windows; sw; sw = sw->next)
313            {
314                    if (sw->wnd == wnd)
315                            continue;
316                    if (sw->desktop != desktop)
317                    {
318                            ewmh_move_to_desktop(sw->wnd, desktop);
319                            sw->desktop = desktop;
320                    }
321            }
322    }
323    
324    
325  static void  static void
326  mwm_hide_decorations(Window wnd)  mwm_hide_decorations(Window wnd)
327  {  {
# Line 1396  ui_init(void) Line 1420  ui_init(void)
1420                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);
1421    
1422          xclip_init();          xclip_init();
1423            ewmh_init();
1424          if (g_seamless_rdp)          if (g_seamless_rdp)
1425                  seamless_init();                  seamless_init();
1426    
# Line 1903  xwin_process_events(void) Line 1928  xwin_process_events(void)
1928                                                            xevent.xexpose.width,                                                            xevent.xexpose.width,
1929                                                            xevent.xexpose.height, xevent.xexpose.x,                                                            xevent.xexpose.height, xevent.xexpose.x,
1930                                                            xevent.xexpose.y);                                                            xevent.xexpose.y);
1931                                            else
1932                                            {
1933                                                    error("Expose for unknown window 0x%lx\n",
1934                                                          xevent.xexpose.window);
1935                                            }
1936                                  }                                  }
1937    
1938                                  break;                                  break;
# Line 1933  xwin_process_events(void) Line 1963  xwin_process_events(void)
1963                                  break;                                  break;
1964                          case PropertyNotify:                          case PropertyNotify:
1965                                  xclip_handle_PropertyNotify(&xevent.xproperty);                                  xclip_handle_PropertyNotify(&xevent.xproperty);
1966                                    if (xevent.xproperty.window == g_wnd)
1967                                            break;
1968                                    if (xevent.xproperty.window == DefaultRootWindow(g_display))
1969                                            break;
1970    
1971                                    /* seamless */
1972                                    sw = seamless_get_window_by_wnd(xevent.xproperty.window);
1973                                    if (!sw)
1974                                            break;
1975    
1976                                    if ((xevent.xproperty.atom == g_net_wm_state_atom)
1977                                        && (xevent.xproperty.state == PropertyNewValue))
1978                                    {
1979                                            sw->state = ewmh_get_window_state(sw->wnd);
1980                                            seamless_send_state(sw->id, sw->state, 0);
1981                                    }
1982    
1983                                    if ((xevent.xproperty.atom == g_net_wm_desktop_atom)
1984                                        && (xevent.xproperty.state == PropertyNewValue))
1985                                    {
1986                                            sw->desktop = ewmh_get_window_desktop(sw->wnd);
1987                                            seamless_all_to_desktop(sw->wnd, sw->desktop);
1988                                    }
1989    
1990                                  break;                                  break;
1991                          case MapNotify:                          case MapNotify:
1992                                  if (!g_seamless_rdp)                                  if (!g_seamless_rdp)
# Line 2987  ui_seamless_toggle() Line 3041  ui_seamless_toggle()
3041  }  }
3042    
3043  void  void
3044  ui_seamless_create_window(unsigned long id, unsigned long flags)  ui_seamless_create_window(unsigned long id, unsigned long parent, unsigned long flags)
3045  {  {
3046          Window wnd;          Window wnd;
3047          XSetWindowAttributes attribs;          XSetWindowAttributes attribs;
3048          XClassHint *classhints;          XClassHint *classhints;
3049            XSizeHints *sizehints;
3050          long input_mask;          long input_mask;
3051          seamless_window *sw;          seamless_window *sw, *sw_parent;
3052    
3053          get_window_attribs(&attribs);          /* Ignore CREATEs for existing windows */
3054            sw = seamless_get_window_by_id(id);
3055            if (sw)
3056                    return;
3057    
3058            get_window_attribs(&attribs);
3059          attribs.override_redirect = False;          attribs.override_redirect = False;
3060    
3061          /* 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,  
3062                              InputOutput, g_visual,                              InputOutput, g_visual,
3063                              CWBackPixel | CWBackingStore | CWOverrideRedirect | CWColormap |                              CWBackPixel | CWBackingStore | CWOverrideRedirect | CWColormap |
3064                              CWBorderPixel, &attribs);                              CWBorderPixel, &attribs);
3065    
3066          XStoreName(g_display, wnd, "rdesktop-seamless");          XStoreName(g_display, wnd, "SeamlessRDP");
3067            ewmh_set_wm_name(wnd, "SeamlessRDP");
3068    
3069          mwm_hide_decorations(wnd);          mwm_hide_decorations(wnd);
3070    
3071          classhints = XAllocClassHint();          classhints = XAllocClassHint();
3072          if (classhints != NULL)          if (classhints != NULL)
3073          {          {
3074                  classhints->res_name = classhints->res_class = "rdesktop";                  classhints->res_name = "rdesktop";
3075                    classhints->res_class = "SeamlessRDP";
3076                  XSetClassHint(g_display, wnd, classhints);                  XSetClassHint(g_display, wnd, classhints);
3077                  XFree(classhints);                  XFree(classhints);
3078          }          }
3079    
3080            /* WM_NORMAL_HINTS */
3081            sizehints = XAllocSizeHints();
3082            if (sizehints != NULL)
3083            {
3084                    sizehints->flags = USPosition;
3085                    XSetWMNormalHints(g_display, wnd, sizehints);
3086                    XFree(sizehints);
3087            }
3088    
3089            /* Handle popups without parents through some ewm hints */
3090            if (parent == 0xFFFFFFFF)
3091                    ewmh_set_window_popup(wnd);
3092            /* Set WM_TRANSIENT_FOR, if necessary */
3093            else if (parent != 0x00000000)
3094            {
3095                    sw_parent = seamless_get_window_by_id(parent);
3096                    if (sw_parent)
3097                            XSetTransientForHint(g_display, wnd, sw_parent->wnd);
3098                    else
3099                            warning("ui_seamless_create_window: No parent window 0x%lx\n", parent);
3100            }
3101    
3102    
3103          /* FIXME: Support for Input Context:s */          /* FIXME: Support for Input Context:s */
3104    
3105          get_input_mask(&input_mask);          get_input_mask(&input_mask);
3106            input_mask |= PropertyChangeMask;
3107    
3108          XSelectInput(g_display, wnd, input_mask);          XSelectInput(g_display, wnd, input_mask);
3109    
         XMapWindow(g_display, wnd);  
   
3110          /* handle the WM_DELETE_WINDOW protocol. FIXME: When killing a          /* handle the WM_DELETE_WINDOW protocol. FIXME: When killing a
3111             seamless window, we could try to close the window on the             seamless window, we could try to close the window on the
3112             serverside, instead of terminating rdesktop */             serverside, instead of terminating rdesktop */
# Line 3035  ui_seamless_create_window(unsigned long Line 3115  ui_seamless_create_window(unsigned long
3115          sw = malloc(sizeof(seamless_window));          sw = malloc(sizeof(seamless_window));
3116          sw->wnd = wnd;          sw->wnd = wnd;
3117          sw->id = id;          sw->id = id;
3118            sw->hints = XAllocWMHints();
3119            sw->hints->flags = 0;
3120          sw->xoffset = 0;          sw->xoffset = 0;
3121          sw->yoffset = 0;          sw->yoffset = 0;
3122          sw->width = 0;          sw->width = 0;
3123          sw->height = 0;          sw->height = 0;
3124            sw->state = SEAMLESSRDP_NOTYETMAPPED;
3125            sw->desktop = 0;
3126          sw->next = g_seamless_windows;          sw->next = g_seamless_windows;
3127          g_seamless_windows = sw;          g_seamless_windows = sw;
3128  }  }
# Line 3048  void Line 3132  void
3132  ui_seamless_destroy_window(unsigned long id, unsigned long flags)  ui_seamless_destroy_window(unsigned long id, unsigned long flags)
3133  {  {
3134          seamless_window *sw;          seamless_window *sw;
         sw = seamless_get_window_by_id(id);  
3135    
3136            sw = seamless_get_window_by_id(id);
3137          if (!sw)          if (!sw)
3138          {          {
3139                  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 3151  ui_seamless_move_window(unsigned long id
3151          seamless_window *sw;          seamless_window *sw;
3152    
3153          sw = seamless_get_window_by_id(id);          sw = seamless_get_window_by_id(id);
   
3154          if (!sw)          if (!sw)
3155          {          {
3156                  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 3172  ui_seamless_move_window(unsigned long id
3172          sw->width = MIN(MIN(width, width + x), g_width - sw->xoffset);          sw->width = MIN(MIN(width, width + x), g_width - sw->xoffset);
3173          sw->height = MIN(MIN(height, height + y), g_height - sw->yoffset);          sw->height = MIN(MIN(height, height + y), g_height - sw->yoffset);
3174    
3175            /* If we move the window in a maximized state, then KDE won't
3176               accept restoration */
3177            switch (sw->state)
3178            {
3179                    case SEAMLESSRDP_MINIMIZED:
3180                    case SEAMLESSRDP_MAXIMIZED:
3181                            return;
3182            }
3183    
3184          /* FIXME: Perhaps use ewmh_net_moveresize_window instead */          /* FIXME: Perhaps use ewmh_net_moveresize_window instead */
3185          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);
3186  }  }
# Line 3100  ui_seamless_settitle(unsigned long id, c Line 3192  ui_seamless_settitle(unsigned long id, c
3192          seamless_window *sw;          seamless_window *sw;
3193    
3194          sw = seamless_get_window_by_id(id);          sw = seamless_get_window_by_id(id);
3195            if (!sw)
3196            {
3197                    warning("ui_seamless_settitle: No information for window 0x%lx\n", id);
3198                    return;
3199            }
3200    
3201            /* FIXME: Might want to convert the name for non-EWMH WMs */
3202          XStoreName(g_display, sw->wnd, title);          XStoreName(g_display, sw->wnd, title);
3203            ewmh_set_wm_name(sw->wnd, title);
3204  }  }
3205    
3206    
# Line 3111  ui_seamless_setstate(unsigned long id, u Line 3210  ui_seamless_setstate(unsigned long id, u
3210          seamless_window *sw;          seamless_window *sw;
3211    
3212          sw = seamless_get_window_by_id(id);          sw = seamless_get_window_by_id(id);
3213            if (!sw)
3214            {
3215                    warning("ui_seamless_setstate: No information for window 0x%lx\n", id);
3216                    return;
3217            }
3218    
3219          switch (state)          switch (state)
3220          {          {
3221                  case SEAMLESSRDP_NORMAL:                  case SEAMLESSRDP_NORMAL:
3222                  case SEAMLESSRDP_MAXIMIZED:                  case SEAMLESSRDP_MAXIMIZED:
3223                          /* FIXME */                          ewmh_change_state(sw->wnd, state);
3224                            XMapWindow(g_display, sw->wnd);
3225                          break;                          break;
3226                  case SEAMLESSRDP_MINIMIZED:                  case SEAMLESSRDP_MINIMIZED:
3227                          XIconifyWindow(g_display, sw->wnd, DefaultScreen(g_display));                          /* EWMH says: "if an Application asks to toggle _NET_WM_STATE_HIDDEN
3228                               the Window Manager should probably just ignore the request, since
3229                               _NET_WM_STATE_HIDDEN is a function of some other aspect of the window
3230                               such as minimization, rather than an independent state." Besides,
3231                               XIconifyWindow is easier. */
3232                            if (sw->state == SEAMLESSRDP_NOTYETMAPPED)
3233                            {
3234                                    sw->hints->flags |= StateHint;
3235                                    sw->hints->initial_state = IconicState;
3236                                    XSetWMHints(g_display, sw->wnd, sw->hints);
3237                                    XMapWindow(g_display, sw->wnd);
3238                            }
3239                            else
3240                                    XIconifyWindow(g_display, sw->wnd, DefaultScreen(g_display));
3241                          break;                          break;
3242                  default:                  default:
3243                          warning("SeamlessRDP: Invalid state %d\n", state);                          warning("SeamlessRDP: Invalid state %d\n", state);
3244                          break;                          break;
3245          }          }
3246    
3247            sw->state = state;
3248    }
3249    
3250    
3251    void
3252    ui_seamless_syncbegin(unsigned long flags)
3253    {
3254            /* Destroy all seamless windows */
3255            while (g_seamless_windows)
3256            {
3257                    XDestroyWindow(g_display, g_seamless_windows->wnd);
3258                    seamless_remove_window(g_seamless_windows);
3259            }
3260  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26