/[rdesktop]/sourceforge.net/trunk/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/trunk/rdesktop/xwin.c

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

revision 831 by jdmeijer, Tue Mar 8 00:43:10 2005 UTC revision 1022 by jsorg71, Thu Sep 29 03:34:33 2005 UTC
# Line 32  extern int g_width; Line 32  extern int g_width;
32  extern int g_height;  extern int g_height;
33  extern int g_xpos;  extern int g_xpos;
34  extern int g_ypos;  extern int g_ypos;
35    extern int g_pos;
36  extern BOOL g_sendmotion;  extern BOOL g_sendmotion;
37  extern BOOL g_fullscreen;  extern BOOL g_fullscreen;
38  extern BOOL g_grab_keyboard;  extern BOOL g_grab_keyboard;
# Line 78  static Pixmap g_backstore = 0; Line 79  static Pixmap g_backstore = 0;
79  static BOOL g_moving_wnd;  static BOOL g_moving_wnd;
80  static int g_move_x_offset = 0;  static int g_move_x_offset = 0;
81  static int g_move_y_offset = 0;  static int g_move_y_offset = 0;
82    static BOOL g_using_full_workarea = False;
83    
84  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
85  extern int g_dsp_fd;  extern int g_dsp_fd;
# Line 136  PixelColour; Line 138  PixelColour;
138                                  XDrawArc(g_display, g_backstore, g_gc, x, y, cx, cy, 0, 360*64); \                                  XDrawArc(g_display, g_backstore, g_gc, x, y, cx, cy, 0, 360*64); \
139                          break; \                          break; \
140                  case 1: /* Filled */ \                  case 1: /* Filled */ \
141                          XFillArc(g_display, g_ownbackstore ? g_backstore : g_wnd, g_gc, x, y, \                          XFillArc(g_display, g_wnd, g_gc, x, y, cx, cy, 0, 360*64); \
                                  cx, cy, 0, 360*64); \  
142                          if (g_ownbackstore) \                          if (g_ownbackstore) \
143                                  XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y); \                                  XFillArc(g_display, g_backstore, g_gc, x, y, cx, cy, 0, 360*64); \
144                          break; \                          break; \
145          } \          } \
146  }  }
# Line 1090  ui_init(void) Line 1091  ui_init(void)
1091          else if (g_width < 0)          else if (g_width < 0)
1092          {          {
1093                  /* Percent of screen */                  /* Percent of screen */
1094                    if (-g_width >= 100)
1095                            g_using_full_workarea = True;
1096                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
1097                  g_width = WidthOfScreen(g_screen) * (-g_width) / 100;                  g_width = WidthOfScreen(g_screen) * (-g_width) / 100;
1098          }          }
# Line 1097  ui_init(void) Line 1100  ui_init(void)
1100          {          {
1101                  /* Fetch geometry from _NET_WORKAREA */                  /* Fetch geometry from _NET_WORKAREA */
1102                  uint32 x, y, cx, cy;                  uint32 x, y, cx, cy;
1103                    g_using_full_workarea = True;
1104    
1105                  if (get_current_workarea(&x, &y, &cx, &cy) == 0)                  if (get_current_workarea(&x, &y, &cx, &cy) == 0)
1106                  {                  {
# Line 1163  ui_create_window(void) Line 1167  ui_create_window(void)
1167          wndwidth = g_fullscreen ? WidthOfScreen(g_screen) : g_width;          wndwidth = g_fullscreen ? WidthOfScreen(g_screen) : g_width;
1168          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
1169    
1170            /* Handle -x-y portion of geometry string */
1171            if (g_xpos < 0 || (g_xpos == 0 && (g_pos & 2)))
1172                    g_xpos = WidthOfScreen(g_screen) + g_xpos - g_width;
1173            if (g_ypos < 0 || (g_ypos == 0 && (g_pos & 4)))
1174                    g_ypos = HeightOfScreen(g_screen) + g_ypos - g_height;
1175    
1176          attribs.background_pixel = BlackPixelOfScreen(g_screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
1177          attribs.border_pixel = WhitePixelOfScreen(g_screen);          attribs.border_pixel = WhitePixelOfScreen(g_screen);
1178          attribs.backing_store = g_ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
# Line 1206  ui_create_window(void) Line 1216  ui_create_window(void)
1216          if (sizehints)          if (sizehints)
1217          {          {
1218                  sizehints->flags = PMinSize | PMaxSize;                  sizehints->flags = PMinSize | PMaxSize;
1219                    if (g_pos)
1220                            sizehints->flags |= PPosition;
1221                  sizehints->min_width = sizehints->max_width = g_width;                  sizehints->min_width = sizehints->max_width = g_width;
1222                  sizehints->min_height = sizehints->max_height = g_height;                  sizehints->min_height = sizehints->max_height = g_height;
1223                  XSetWMNormalHints(g_display, g_wnd, sizehints);                  XSetWMNormalHints(g_display, g_wnd, sizehints);
# Line 1218  ui_create_window(void) Line 1230  ui_create_window(void)
1230          }          }
1231    
1232          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
1233                  VisibilityChangeMask | FocusChangeMask;                  VisibilityChangeMask | FocusChangeMask | StructureNotifyMask;
1234    
1235          if (g_sendmotion)          if (g_sendmotion)
1236                  input_mask |= PointerMotionMask;                  input_mask |= PointerMotionMask;
# Line 1332  xwin_toggle_fullscreen(void) Line 1344  xwin_toggle_fullscreen(void)
1344          }          }
1345  }  }
1346    
1347  /* Process all events in Xlib queue  static void
1348    handle_button_event(XEvent xevent, BOOL down)
1349    {
1350            uint16 button, flags = 0;
1351            g_last_gesturetime = xevent.xbutton.time;
1352            button = xkeymap_translate_button(xevent.xbutton.button);
1353            if (button == 0)
1354                    return;
1355    
1356            if (down)
1357                    flags = MOUSE_FLAG_DOWN;
1358    
1359            /* Stop moving window when button is released, regardless of cursor position */
1360            if (g_moving_wnd && (xevent.type == ButtonRelease))
1361                    g_moving_wnd = False;
1362    
1363            /* If win_button_size is nonzero, enable single app mode */
1364            if (xevent.xbutton.y < g_win_button_size)
1365            {
1366                    /*  Check from right to left: */
1367                    if (xevent.xbutton.x >= g_width - g_win_button_size)
1368                    {
1369                            /* The close button, continue */
1370                            ;
1371                    }
1372                    else if (xevent.xbutton.x >= g_width - g_win_button_size * 2)
1373                    {
1374                            /* The maximize/restore button. Do not send to
1375                               server.  It might be a good idea to change the
1376                               cursor or give some other visible indication
1377                               that rdesktop inhibited this click */
1378                            if (xevent.type == ButtonPress)
1379                                    return;
1380                    }
1381                    else if (xevent.xbutton.x >= g_width - g_win_button_size * 3)
1382                    {
1383                            /* The minimize button. Iconify window. */
1384                            if (xevent.type == ButtonRelease)
1385                            {
1386                                    /* Release the mouse button outside the minimize button, to prevent the
1387                                       actual minimazation to happen */
1388                                    rdp_send_input(time(NULL), RDP_INPUT_MOUSE, button, 1, 1);
1389                                    XIconifyWindow(g_display, g_wnd, DefaultScreen(g_display));
1390                                    return;
1391                            }
1392                    }
1393                    else if (xevent.xbutton.x <= g_win_button_size)
1394                    {
1395                            /* The system menu. Ignore. */
1396                            if (xevent.type == ButtonPress)
1397                                    return;
1398                    }
1399                    else
1400                    {
1401                            /* The title bar. */
1402                            if (xevent.type == ButtonPress)
1403                            {
1404                                    if (!g_fullscreen && g_hide_decorations && !g_using_full_workarea)
1405                                    {
1406                                            g_moving_wnd = True;
1407                                            g_move_x_offset = xevent.xbutton.x;
1408                                            g_move_y_offset = xevent.xbutton.y;
1409                                    }
1410                                    return;
1411                            }
1412                    }
1413            }
1414    
1415            rdp_send_input(time(NULL), RDP_INPUT_MOUSE,
1416                           flags | button, xevent.xbutton.x, xevent.xbutton.y);
1417    }
1418    
1419    /* Process events in Xlib queue
1420     Returns 0 after user quit, 1 otherwise */     Returns 0 after user quit, 1 otherwise */
1421  static int  static int
1422  xwin_process_events(void)  xwin_process_events(void)
1423  {  {
1424          XEvent xevent;          XEvent xevent;
1425          KeySym keysym;          KeySym keysym;
         uint16 button, flags;  
1426          uint32 ev_time;          uint32 ev_time;
         key_translation tr;  
1427          char str[256];          char str[256];
1428          Status status;          Status status;
1429            int events = 0;
1430    
1431          while (XPending(g_display) > 0)          while ((XPending(g_display) > 0) && events++ < 20)
1432          {          {
1433                  XNextEvent(g_display, &xevent);                  XNextEvent(g_display, &xevent);
1434    
# Line 1355  xwin_process_events(void) Line 1438  xwin_process_events(void)
1438                          continue;                          continue;
1439                  }                  }
1440    
                 flags = 0;  
   
1441                  switch (xevent.type)                  switch (xevent.type)
1442                  {                  {
1443                          case VisibilityNotify:                          case VisibilityNotify:
# Line 1393  xwin_process_events(void) Line 1474  xwin_process_events(void)
1474                                                        str, sizeof(str), &keysym, NULL);                                                        str, sizeof(str), &keysym, NULL);
1475                                  }                                  }
1476    
1477                                  DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym,                                  DEBUG_KBD(("KeyPress for keysym (0x%lx, %s)\n", keysym,
1478                                             get_ksname(keysym)));                                             get_ksname(keysym)));
1479    
1480                                  ev_time = time(NULL);                                  ev_time = time(NULL);
1481                                  if (handle_special_keys(keysym, xevent.xkey.state, ev_time, True))                                  if (handle_special_keys(keysym, xevent.xkey.state, ev_time, True))
1482                                          break;                                          break;
1483    
1484                                  tr = xkeymap_translate_key(keysym,                                  xkeymap_send_keys(keysym, xevent.xkey.keycode, xevent.xkey.state,
1485                                                             xevent.xkey.keycode, xevent.xkey.state);                                                    ev_time, True, 0);
   
                                 if (tr.scancode == 0)  
                                         break;  
   
                                 save_remote_modifiers(tr.scancode);  
                                 ensure_remote_modifiers(ev_time, tr);  
                                 rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);  
                                 restore_remote_modifiers(ev_time, tr.scancode);  
   
1486                                  break;                                  break;
1487    
1488                          case KeyRelease:                          case KeyRelease:
# Line 1418  xwin_process_events(void) Line 1490  xwin_process_events(void)
1490                                  XLookupString((XKeyEvent *) & xevent, str,                                  XLookupString((XKeyEvent *) & xevent, str,
1491                                                sizeof(str), &keysym, NULL);                                                sizeof(str), &keysym, NULL);
1492    
1493                                  DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym,                                  DEBUG_KBD(("\nKeyRelease for keysym (0x%lx, %s)\n", keysym,
1494                                             get_ksname(keysym)));                                             get_ksname(keysym)));
1495    
1496                                  ev_time = time(NULL);                                  ev_time = time(NULL);
1497                                  if (handle_special_keys(keysym, xevent.xkey.state, ev_time, False))                                  if (handle_special_keys(keysym, xevent.xkey.state, ev_time, False))
1498                                          break;                                          break;
1499    
1500                                  tr = xkeymap_translate_key(keysym,                                  xkeymap_send_keys(keysym, xevent.xkey.keycode, xevent.xkey.state,
1501                                                             xevent.xkey.keycode, xevent.xkey.state);                                                    ev_time, False, 0);
   
                                 if (tr.scancode == 0)  
                                         break;  
   
                                 rdp_send_scancode(ev_time, RDP_KEYRELEASE, tr.scancode);  
1502                                  break;                                  break;
1503    
1504                          case ButtonPress:                          case ButtonPress:
1505                                  flags = MOUSE_FLAG_DOWN;                                  handle_button_event(xevent, True);
1506                                  /* fall through */                                  break;
1507    
1508                          case ButtonRelease:                          case ButtonRelease:
1509                                  g_last_gesturetime = xevent.xbutton.time;                                  handle_button_event(xevent, False);
                                 button = xkeymap_translate_button(xevent.xbutton.button);  
                                 if (button == 0)  
                                         break;  
   
                                 /* If win_button_size is nonzero, enable single app mode */  
                                 if (xevent.xbutton.y < g_win_button_size)  
                                 {  
                                         /* Stop moving window when button is released, regardless of cursor position */  
                                         if (g_moving_wnd && (xevent.type == ButtonRelease))  
                                                 g_moving_wnd = False;  
   
                                         /*  Check from right to left: */  
   
                                         if (xevent.xbutton.x >= g_width - g_win_button_size)  
                                         {  
                                                 /* The close button, continue */  
                                                 ;  
                                         }  
                                         else if (xevent.xbutton.x >=  
                                                  g_width - g_win_button_size * 2)  
                                         {  
                                                 /* The maximize/restore button. Do not send to  
                                                    server.  It might be a good idea to change the  
                                                    cursor or give some other visible indication  
                                                    that rdesktop inhibited this click */  
                                                 break;  
                                         }  
                                         else if (xevent.xbutton.x >=  
                                                  g_width - g_win_button_size * 3)  
                                         {  
                                                 /* The minimize button. Iconify window. */  
                                                 XIconifyWindow(g_display, g_wnd,  
                                                                DefaultScreen(g_display));  
                                                 break;  
                                         }  
                                         else if (xevent.xbutton.x <= g_win_button_size)  
                                         {  
                                                 /* The system menu. Ignore. */  
                                                 break;  
                                         }  
                                         else  
                                         {  
                                                 /* The title bar. */  
                                                 if ((xevent.type == ButtonPress) && !g_fullscreen  
                                                     && g_hide_decorations)  
                                                 {  
                                                         g_moving_wnd = True;  
                                                         g_move_x_offset = xevent.xbutton.x;  
                                                         g_move_y_offset = xevent.xbutton.y;  
                                                 }  
                                                 break;  
   
                                         }  
                                 }  
   
                                 rdp_send_input(time(NULL), RDP_INPUT_MOUSE,  
                                                flags | button, xevent.xbutton.x, xevent.xbutton.y);  
1510                                  break;                                  break;
1511    
1512                          case MotionNotify:                          case MotionNotify:
# Line 1589  xwin_process_events(void) Line 1599  xwin_process_events(void)
1599                          case PropertyNotify:                          case PropertyNotify:
1600                                  xclip_handle_PropertyNotify(&xevent.xproperty);                                  xclip_handle_PropertyNotify(&xevent.xproperty);
1601                                  break;                                  break;
1602                            case MapNotify:
1603                                    rdp_send_client_window_status(1);
1604                                    break;
1605                            case UnmapNotify:
1606                                    rdp_send_client_window_status(0);
1607                                    break;
1608                  }                  }
1609          }          }
1610          /* Keep going */          /* Keep going */
# Line 2263  ui_polygon(uint8 opcode, Line 2279  ui_polygon(uint8 opcode,
2279  }  }
2280    
2281  void  void
2282    ui_polyline(uint8 opcode,
2283                /* dest */ POINT * points, int npoints,
2284                /* pen */ PEN * pen)
2285    {
2286            /* TODO: set join style */
2287            SET_FUNCTION(opcode);
2288            SET_FOREGROUND(pen->colour);
2289            XDrawLines(g_display, g_wnd, g_gc, (XPoint *) points, npoints, CoordModePrevious);
2290            if (g_ownbackstore)
2291                    XDrawLines(g_display, g_backstore, g_gc, (XPoint *) points, npoints,
2292                               CoordModePrevious);
2293            RESET_FUNCTION(opcode);
2294    }
2295    
2296    void
2297  ui_ellipse(uint8 opcode,  ui_ellipse(uint8 opcode,
2298             /* mode */ uint8 fillmode,             /* mode */ uint8 fillmode,
2299             /* dest */ int x, int y, int cx, int cy,             /* dest */ int x, int y, int cx, int cy,
# Line 2376  ui_draw_glyph(int mixmode, Line 2407  ui_draw_glyph(int mixmode,
2407  }  }
2408    
2409  void  void
2410  ui_draw_text(uint8 font, uint8 flags, int mixmode, int x, int y,  ui_draw_text(uint8 font, uint8 flags, uint8 opcode, int mixmode, int x, int y,
2411               int clipx, int clipy, int clipcx, int clipcy,               int clipx, int clipy, int clipcx, int clipcy,
2412               int boxx, int boxy, int boxcx, int boxcy, int bgcolour,               int boxx, int boxy, int boxcx, int boxcy, BRUSH * brush,
2413               int fgcolour, uint8 * text, uint8 length)               int bgcolour, int fgcolour, uint8 * text, uint8 length)
2414  {  {
2415            /* TODO: use brush appropriately */
2416    
2417          FONTGLYPH *glyph;          FONTGLYPH *glyph;
2418          int i, j, xyoffset, x1, y1;          int i, j, xyoffset, x1, y1;
2419          DATABLOB *entry;          DATABLOB *entry;

Legend:
Removed from v.831  
changed lines
  Added in v.1022

  ViewVC Help
Powered by ViewVC 1.1.26