Advertisement
lehjr

xextf86vm.cpp

Jun 27th, 2012
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 20.52 KB | None | 0 0
  1. /*
  2.     Copyright (C) 1998 by Jorrit Tyberghein
  3.     Copyright (C) 2001 by Samuel Humphreys
  4.  
  5.     This library is free software; you can redistribute it and/or
  6.     modify it under the terms of the GNU Library General Public
  7.     License as published by the Free Software Foundation; either
  8.     version 2 of the License, or (at your option) any later version.
  9.  
  10.     This library is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.     Library General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU Library General Public
  16.     License along with this library; if not, write to the Free
  17.     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #include <stdarg.h>
  21. #include "cssysdef.h"
  22. #include "csutil/sysfunc.h"
  23. #include "csutil/scf.h"
  24. #include "ivaria/reporter.h"
  25. #include "csgeom/csrect.h"
  26. #include "csutil/cfgacc.h"
  27. #include "xextf86vm.h"
  28. //#include "xextxrandr.h"
  29.  
  30.  
  31. SCF_IMPLEMENT_FACTORY (csXExtF86VM)
  32.  
  33. csXExtF86VM::csXExtF86VM (iBase* parent)
  34.   : scfImplementationType (this, parent)
  35. {
  36.   dpy = 0;
  37.   screen_num = 0;
  38.   width = height = 0;
  39.   fs_win = wm_win = ctx_win = 0;
  40. }
  41.  
  42. csXExtF86VM::~csXExtF86VM ()
  43. {
  44. }
  45. //=========================================================
  46. //    C H E C K   F U L L S C R E E N   S E T T I N G                          
  47. //=========================================================
  48. bool csXExtF86VM::Initialize (iObjectRegistry *object_reg)
  49. {
  50.   this->object_reg = object_reg;
  51.   csConfigAccess Config(object_reg, "/config/video.cfg");
  52.   full_screen = Config->GetBool ("Video.FullScreen", false);
  53.   return true;
  54. }
  55.  
  56. //=========================================================
  57. //    E R R O R   R E P O R T I N G                        
  58. //=========================================================
  59. void csXExtF86VM::Report (int severity, const char* msg, ...)
  60. {
  61.   va_list arg;
  62.   va_start (arg, msg);
  63.   csRef<iReporter> rep (csQueryRegistry<iReporter> (object_reg));
  64.   if (rep)
  65.     rep->ReportV (severity, "crystalspace.window.x.extf86vm", msg, arg);
  66.   else
  67.   {
  68.     csPrintfV (msg, arg);
  69.     csPrintf ("\n");
  70.   }
  71.   va_end (arg);
  72. }
  73.  
  74. //=========================================================
  75. //    O P E N   D I S P L A Y                              
  76. //=========================================================
  77. bool csXExtF86VM::Open (Display *dpy, int screen_num,
  78.             XVisualInfo *xvis, Colormap cmap)
  79. {
  80.   if (!ctx_win || !wm_win)
  81.   {
  82.     Report (CS_REPORTER_SEVERITY_ERROR, "No Windows Set\n");
  83.     return false;
  84.   }
  85.  
  86.   this->dpy = dpy;
  87.   this->screen_num = screen_num;
  88.   unsigned long cw_fs_mask  = (CWOverrideRedirect |
  89.                    CWBorderPixel |
  90.                    (cmap ? CWColormap : 0));
  91.   XSetWindowAttributes swa;
  92.   memset (&swa, 0, sizeof(swa));
  93.   swa.colormap = cmap;
  94.   swa.override_redirect = True;
  95.   swa.background_pixel = 0;
  96.   swa.border_pixel = 0;
  97.   swa.event_mask = 0;
  98.  
  99.   fs_win = XCreateWindow (dpy,
  100.               RootWindow (dpy, screen_num),
  101.               0, 0, 1, 1,
  102.               0,
  103.               xvis->depth,
  104.               InputOutput,
  105.               xvis->visual,
  106.               cw_fs_mask,
  107.               &swa);
  108.  
  109.   XStoreName (dpy, fs_win, "Full Screen");
  110.   XSetWindowBackground (dpy, fs_win, BlackPixel (dpy, screen_num));
  111.   XSelectInput (dpy, fs_win, 0);
  112.  
  113.   if (full_screen)
  114.   {
  115.     full_screen = false;
  116.     EnterFullScreen ();
  117.     return full_screen;
  118.   }
  119.   return true;
  120. }
  121.  
  122. //=========================================================
  123. //    C L O S E   D I S P L A Y
  124. //=========================================================
  125. void csXExtF86VM::Close ()
  126. {
  127.   ctx_win = wm_win = 0;
  128.   if (full_screen)
  129.     LeaveFullScreen ();
  130.   XDestroyWindow (dpy, fs_win);
  131.   fs_win = 0;
  132. }
  133.  
  134. //=========================================================
  135. //    S E T   F U L L S C R E E N
  136. //=========================================================
  137. bool csXExtF86VM::SetFullScreen (bool yesno)
  138. {
  139.   if (!ctx_win)
  140.   {
  141.     // In initialization phase and configuring
  142.     full_screen = yesno;
  143.     return false;
  144.   }
  145.   if (full_screen != yesno)
  146.   {
  147.     if (yesno)
  148.       EnterFullScreen ();
  149.     else
  150.       LeaveFullScreen ();
  151.     return (full_screen == yesno);
  152.   }
  153.   return false;
  154. }
  155.  
  156. //-----------------------------------------------------------------------------
  157. #ifndef HAVE_XRANDR //   X F 8 6 V M
  158. //-----------------------------------------------------------------------------
  159. //=========================================================
  160. //    X F 8 6 V M   G E T   R E S O L U T I O N   I N F O
  161. //=========================================================
  162. static bool GetModeInfo (Display *dpy, int scr, XF86VidModeModeInfo *info)
  163. {
  164.   XF86VidModeModeLine *l;
  165.  
  166.   l = (XF86VidModeModeLine *) ((char *)info + sizeof(info->dotclock));
  167.  
  168.   return XF86VidModeGetModeLine (dpy, scr, (int *)&info->dotclock, l);
  169. }
  170.  
  171. //=========================================================
  172. //    X F 8 6 V M   C H A N G E   M O D E S
  173. //=========================================================
  174. void csXExtF86VM::ChangeVideoMode (int zoom)
  175. {
  176.   XF86VidModeLockModeSwitch (dpy, screen_num, false);
  177.   if (XF86VidModeSwitchMode (dpy, screen_num, zoom))
  178.   {
  179.     if (!GetModeInfo (dpy, screen_num, &fs_mode))
  180.       Report (CS_REPORTER_SEVERITY_ERROR, "Unable to retrieve mode info ");
  181.     width = fs_mode.hdisplay;
  182.     height = fs_mode.vdisplay;
  183.     XResizeWindow (dpy, fs_win, fs_mode.hdisplay, fs_mode.vdisplay);
  184.     XF86VidModeSetViewPort(dpy, screen_num, 0, 0);
  185.     Report (CS_REPORTER_SEVERITY_NOTIFY, "%s VIDEOMODE: %d, %d\n",
  186.         zoom == -1 ? "UP" : "DOWN",
  187.         width, height);
  188.   }
  189.   XF86VidModeLockModeSwitch (dpy, screen_num, true);
  190. }
  191.  
  192. //=========================================================
  193. //    X F 8 6 V M   C O M P A R E   M O D E S
  194. //=========================================================
  195. static int cmp_modes (const void *va, const void *vb)
  196. {
  197.   XF86VidModeModeInfo *a = *(XF86VidModeModeInfo **) va;
  198.   XF86VidModeModeInfo *b = *(XF86VidModeModeInfo **) vb;
  199.  
  200.   if (a->hdisplay > b->hdisplay)
  201.     return -1;
  202.   else
  203.     return b->vdisplay - a->vdisplay;
  204. }
  205.  
  206. //=========================================================
  207. //    X F 8 6 V M   F I N D   B E S T   M O D E
  208. //=========================================================
  209. void csXExtF86VM::FindBestMode (int ctx_width, int ctx_height)
  210. {
  211.   XF86VidModeModeLine mode;
  212.   XF86VidModeModeInfo **modes;
  213.   int i, nModes, best_mode = 0;
  214.   bool valid = false;
  215.   unsigned int diff;
  216.   unsigned int best_diff = (unsigned int) -1;
  217.   if (XF86VidModeGetModeLine(dpy, screen_num, &i, &mode)
  218.    && XF86VidModeGetAllModeLines (dpy, screen_num, &nModes, &modes))
  219.   {
  220.     qsort (modes, nModes, sizeof (*modes), cmp_modes);
  221.  
  222.     // find best full screen mode
  223.     for (i = nModes - 1; i >= 0; --i)
  224.     {
  225.       if (modes[i]->hdisplay >= ctx_width && modes[i]->vdisplay >= ctx_height)
  226.       {
  227.         fs_mode = *modes[i];
  228.     valid = true;
  229.         break;
  230.       }
  231.       diff = ctx_width - modes[i]->hdisplay;
  232.       if (diff < best_diff)
  233.     best_mode = i;
  234.     }
  235.     if (!valid)
  236.       fs_mode = *modes[best_mode];
  237.  
  238.     XFree (modes);
  239.   }
  240. }
  241.  
  242. //=========================================================
  243. //    X F 8 6 V M   S W I T C H   M O D E
  244. //=========================================================
  245. bool csXExtF86VM::SwitchMode (XF86VidModeModeInfo *to_mode,
  246.                   XF86VidModeModeInfo *from_mode,
  247.                   bool lock, int vp_x, int vp_y)
  248. {
  249.   XF86VidModeLockModeSwitch (dpy, screen_num, lock);
  250.   if (to_mode->hdisplay != from_mode->hdisplay ||
  251.       to_mode->vdisplay != from_mode->vdisplay)
  252.   {
  253.     if (!XF86VidModeSwitchToMode (dpy, screen_num, to_mode))
  254.     {
  255.       Report (CS_REPORTER_SEVERITY_ERROR, "Unable to restore mode %hux%hu",
  256.           to_mode->hdisplay, to_mode->vdisplay);
  257.       return false;
  258.     }
  259.   }
  260.   XF86VidModeSetViewPort(dpy, screen_num, vp_x, vp_y);
  261.   return true;
  262. }
  263.  
  264. //-----------------------------------------------------------------------------
  265. #else  //           X R A N D R
  266. //-----------------------------------------------------------------------------
  267.  
  268. //=========================================================
  269. //    X R A N D R   G E T   R E S O L U T I O N   I N F O
  270. //=========================================================
  271. static bool GetResInfo (Display *dpy, int scr, XRANDR_SCRN_CFG *info)
  272. {
  273.   XRRScreenConfiguration *sc;
  274.   XRRScreenSize *size_list;
  275.   int num_sizes, temp_idx;
  276.   Rotation current_rotation;
  277.  
  278.   sc = XRRGetScreenInfo(dpy, RootWindow (dpy, scr));
  279.   if (sc)
  280.   {  
  281.     temp_idx = XRRConfigCurrentConfiguration (sc, &current_rotation);
  282.     size_list = XRRConfigSizes( sc, &num_sizes );
  283.     info->res_idx = temp_idx;
  284.     info->rotation = current_rotation;
  285.     info->width = size_list[temp_idx].width;
  286.     info->height = size_list[temp_idx].height;
  287.     info->num_sizes = num_sizes;    
  288.  
  289.     XRRFreeScreenConfigInfo(sc);
  290.     return true;
  291.   }  
  292.   return false;
  293. }
  294.  
  295. //=========================================================
  296. //    X R A N D R   C H A N G E   R E S O L U T I O N S
  297. //=========================================================
  298. /*
  299.  I used xvidtune to help guess which way "zoom" was supposed to work
  300.  so hopefully I got it right
  301.  way more code than the xf86vm version, but if it works who cares
  302.  
  303. */
  304. void csXExtF86VM::ChangeVideoRes (int zoom)
  305. {
  306.   XRANDR_SCRN_CFG current_scrn_info;
  307.   XRRScreenConfiguration *sc;
  308.   int res_index;
  309.   bool valid;
  310.   sc = XRRGetScreenInfo(dpy, RootWindow (dpy, screen_num));
  311.  
  312.   if (GetResInfo (dpy, screen_num, &current_scrn_info)) // if valid info
  313.   {
  314.     // going to smaller resolution
  315.     if (zoom > 0)
  316.     {
  317.       res_index = current_scrn_info.res_idx +1;
  318.       csPrintf ("going to smaller resolution\n");
  319.       if (current_scrn_info.res_idx +1 > current_scrn_info.num_sizes)
  320.       {
  321.         valid = true;
  322.       }
  323.     }
  324.     // going to larger resolution
  325.     else
  326.     {
  327.       res_index = current_scrn_info.res_idx -1;
  328.       csPrintf ("going to larger resolution\n");
  329.       if (current_scrn_info.res_idx > 0)
  330.       {
  331.         valid = true;      
  332.       }
  333.     }
  334.     if (valid)
  335.     {
  336.       XRRSetScreenConfig(dpy, sc, RootWindow (dpy, screen_num),
  337.                            res_index,current_scrn_info.rotation,
  338.                            CurrentTime);
  339.  
  340.       width = current_scrn_info.width;
  341.       height = current_scrn_info.height;
  342.  
  343.       XResizeWindow (dpy, fs_win, fs_scn_cfg.width, fs_scn_cfg.height);
  344.       Report (CS_REPORTER_SEVERITY_NOTIFY, "%s VIDEOMODE: %d, %d\n",
  345.         zoom == -1 ? "UP" : "DOWN",
  346.         width, height);
  347.     }
  348.   }
  349.   else
  350.     Report (CS_REPORTER_SEVERITY_ERROR, "Unable to retrieve mode info ");
  351.   XRRFreeScreenConfigInfo(sc);
  352. }
  353.  
  354. //=========================================================
  355. //    X R A N D R   F I N D   B E S T   R E S O L U T I O N
  356. //=========================================================
  357. /*
  358. Unlike XF86VM extensions, the XRANDR extensions use an index value to set
  359. the screen size
  360. */
  361. void csXExtF86VM::FindBestRes (int ctx_width, int ctx_height)
  362. {
  363.   // common variables
  364.   bool valid = false;
  365.   unsigned int diff;
  366.   unsigned int best_diff = (unsigned int) -1;
  367.  
  368.   // XRANDR variables
  369.   int j, current_index, num_sizes, best_size_idx = 0;
  370.   Rotation current_rotation;
  371.   XRRScreenConfiguration *sc;
  372.   XRRScreenSize *size_list;
  373.  
  374.   sc = XRRGetScreenInfo(dpy, RootWindow (dpy, screen_num));
  375.   size_list = XRRConfigSizes( sc, &num_sizes );
  376.  
  377.   // just looking for the rotation
  378.   current_index = XRRConfigCurrentConfiguration (sc, &current_rotation);
  379.   csPrintf ("Testing XRANDR code:\n");
  380.   csPrintf ("looking at sizes on screen: %d\n", screen_num);
  381.  
  382.   // find best full screen mode  
  383.   for (j = num_sizes - 1; j >= 0; --j)
  384.   {
  385.     csPrintf ("size_list[%d].width:  %hu  Number of display pixels horizontally\n", j, size_list[j].width);
  386.     csPrintf ("size_list[%d].height: %hu  Number of display pixels vertically\n\n", j, size_list[j].height);
  387.  
  388.     if ((size_list[j].width >= ctx_width) && (size_list[j].height >= ctx_height))
  389.     {
  390.       best_size_idx = j;
  391.       valid = true;
  392.       break;
  393.     }
  394.     diff = ctx_width - size_list[j].width;
  395.     if (diff < best_diff)
  396.     best_size_idx = j;
  397.   }
  398.  
  399.   if (!valid)
  400.   {
  401.     csPrintf ("No valid screen resolution match found!\n");
  402.     best_size_idx = 0;
  403.   }  
  404.  
  405.   fs_scn_cfg.width     = size_list[best_size_idx].width;
  406.   fs_scn_cfg.height    = size_list[best_size_idx].height;
  407.   fs_scn_cfg.res_idx   = best_size_idx;
  408.   fs_scn_cfg.rotation  = current_rotation;
  409.   fs_scn_cfg.num_sizes = num_sizes;
  410.  
  411.   XRRFreeScreenConfigInfo(sc);
  412.   csPrintf ("XRANDR chose %hux%hu as best resolution.\n",
  413.            size_list[best_size_idx].width, size_list[best_size_idx].height);
  414. }
  415.  
  416. //=========================================================
  417. //    X R A N D R   S W I T C H   R E S O L U T I O N
  418. //=========================================================
  419. bool csXExtF86VM::SwitchRes ( XRANDR_SCRN_CFG *to_mode,
  420.                        XRANDR_SCRN_CFG *from_mode)
  421. {
  422.   // XRANDR variables
  423.   Rotation current_rotation;
  424.   XRRScreenConfiguration *sc;
  425.   int test1, major_version, minor_version;
  426.   test1 = XRRQueryVersion (dpy, &major_version, &minor_version);
  427.   csPrintf ("test1 %hu, major version:%d, minor version %d\n\n",
  428.             test1, major_version, minor_version);
  429.  
  430.   csPrintf ("Attempting to switch resolution on screen_num: %d\n", screen_num);
  431.   csPrintf ("to_mode->width:     %hu\n", to_mode->width);
  432.   csPrintf ("to_mode->height:    %hu\n", to_mode->height);
  433.   csPrintf ("to_mode->rotation:  %hu\n", to_mode->rotation);
  434.   csPrintf ("to_mode->res_idx:   %hu\n", to_mode->res_idx);
  435.   csPrintf ("to_mode->num_sizes: %hu\n\n", to_mode->num_sizes);
  436.  
  437.   csPrintf ("From resolution:\n");
  438.   csPrintf ("from_mode->width:     %hu\n", from_mode->width);
  439.   csPrintf ("from_mode->height:    %hu\n", from_mode->height);
  440.   csPrintf ("from_mode->rotation:  %hu\n", from_mode->rotation);
  441.   csPrintf ("from_mode->res_idx:   %hu\n", from_mode->res_idx);
  442.   csPrintf ("from_mode->num_sizes: %hu\n\n", from_mode->num_sizes);
  443.  
  444.   sc = XRRGetScreenInfo(dpy, RootWindow (dpy, screen_num));
  445.   if (sc)
  446.   {
  447.     if (to_mode->width != from_mode->width ||
  448.         to_mode->height != from_mode->height)
  449.     {
  450.       int status = (XRRSetScreenConfig(dpy, sc, RootWindow (dpy, screen_num),
  451.                            to_mode->res_idx,to_mode->rotation,
  452.                            CurrentTime));
  453.       csPrintf ("Result:\n");
  454.       switch (status)
  455.       {
  456.         case RRSetConfigSuccess:
  457.           csPrintf ("RRSetConfigSuccess\n");
  458.           break;
  459.         case GrabNotViewable:
  460.           csPrintf ("RRSetConfigInvalidConfigTime\n");
  461.           break;
  462.         case GrabFrozen:
  463.           csPrintf ("RRSetConfigInvalidTime\n");
  464.           break;
  465.         case GrabInvalidTime:
  466.           csPrintf ("RRSetConfigFailed\n");
  467.           break;
  468.         default :
  469.           csPrintf ("Unknown error\n");
  470.           break;
  471.       }
  472.  
  473.       // return of 0 indicates successful change, anything else is error value
  474.       if (status != RRSetConfigSuccess)
  475.       {
  476.         Report (CS_REPORTER_SEVERITY_ERROR, "Unable to restore mode %hux%hu",
  477.             to_mode->width, to_mode->height);
  478.         return false;
  479.       }
  480.     }
  481.     XRRFreeScreenConfigInfo(sc);
  482.     sleep(3);
  483.     return true;
  484.   }
  485.   return false;
  486. }
  487. #endif
  488.  
  489. //=========================================================
  490. //    E N T E R   F U L L S C R E E N
  491. //=========================================================
  492. void csXExtF86VM::EnterFullScreen ()
  493. {
  494.   XWindowAttributes wa;
  495.   // only switch if needed
  496.   if (full_screen)
  497.     return;
  498.   if (!XGetWindowAttributes (dpy, ctx_win, &wa))
  499.     return;
  500.  
  501. #ifndef HAVE_XRANDR
  502.   FindBestMode (wa.width, wa.height);
  503.   #ifdef CS_DEBUG
  504.     csPrintf ("Entering fullscreen: win %d, %d to fs_mode %hu, %hu\n\n",
  505.       wa.width, wa.height, fs_mode.hdisplay, fs_mode.vdisplay);
  506.   #endif        
  507.   XResizeWindow (dpy, fs_win, fs_mode.hdisplay, fs_mode.vdisplay);
  508. #else
  509.   FindBestRes (wa.width, wa.height);
  510.   #ifdef CS_DEBUG
  511.     csPrintf ("Entering fullscreen: win %d, %d to fs_mode %hu, %hu\n\n",
  512.       wa.width, wa.height, fs_scn_cfg.width, fs_scn_cfg.height);
  513.   #endif        
  514.   XResizeWindow (dpy, fs_win, fs_scn_cfg.width, fs_scn_cfg.height);
  515. #endif
  516.  
  517.   XClearWindow (dpy, fs_win);
  518.   XMapRaised (dpy, fs_win);
  519.  
  520. #ifndef HAVE_XRANDR
  521.   //-xf86vm
  522.   // save current display information
  523.   GetModeInfo (dpy, screen_num, &wm_mode);
  524.   XF86VidModeGetViewPort (dpy, screen_num, &viewport_x, &viewport_y);
  525. #else
  526.   //-xrandr
  527.   // save current display information
  528.   GetResInfo (dpy, screen_num , &wm_scn_cfg);
  529.   // no viewport info for xrandr
  530. #endif
  531.  
  532.   int test1 = XGrabPointer (dpy, fs_win, True, 0, GrabModeAsync, GrabModeAsync, fs_win, None, CurrentTime);
  533.   int test2 = XGrabKeyboard (dpy, fs_win, True, GrabModeAsync, GrabModeAsync, CurrentTime);
  534.  
  535.   csPrintf ("XGrabPointer: ");
  536.   switch( test1 )
  537.   {
  538.     case AlreadyGrabbed:
  539.       csPrintf ("AlreadyGrabbed\n");
  540.       break;
  541.     case GrabNotViewable:
  542.       csPrintf ("GrabNotViewable\n");
  543.       break;
  544.     case GrabFrozen:
  545.       csPrintf ("GrabFrozen\n");
  546.       break;
  547.     case GrabInvalidTime:
  548.       csPrintf ("XGrGrabInvalidTime\n");
  549.       break;
  550.     case GrabSuccess:
  551.       csPrintf ("GrabSuccess\n");
  552.       break;
  553.     default :
  554.       csPrintf ("Unknown error\n");
  555.       break;
  556.   }
  557.  
  558.   csPrintf ("XGrabKeyboard: ");
  559.   switch( test2 )
  560.   {
  561.     case AlreadyGrabbed:
  562.       csPrintf ("AlreadyGrabbed\n");
  563.       break;
  564.     case GrabNotViewable:
  565.       csPrintf ("GrabNotViewable\n");
  566.       break;
  567.     case GrabFrozen:
  568.       csPrintf ("GrabFrozen\n");
  569.       break;    
  570.     case GrabInvalidTime:
  571.       csPrintf ("GrabInvalidTime\n");
  572.       break;
  573.     case GrabSuccess:
  574.       csPrintf ("GrabSuccess\n");
  575.       break;
  576.     default :
  577.       csPrintf ("Unknown error\n");
  578.       break;
  579.   }
  580.  
  581.  
  582. #ifndef HAVE_XRANDR
  583.   bool test3 = SwitchMode (&fs_mode, &wm_mode, true, 0, 0);
  584.   csPrintf ("SwitchMode:     %d\n\n", test3);
  585. #else
  586.  bool test3 = SwitchRes (&fs_scn_cfg, &wm_scn_cfg);
  587.   csPrintf ("SwitchRes:     %d\n\n", test3);
  588. #endif
  589.  
  590.  
  591.  
  592.  
  593. /*
  594.   // grab pointer and keyboard in fullscreen mode
  595.   if ((XGrabPointer (dpy, fs_win, True,
  596.             0, GrabModeAsync, GrabModeAsync,
  597.             fs_win, None, CurrentTime) == GrabSuccess) &&
  598.       //(XGrabKeyboard (dpy, wm_win, True, GrabModeAsync,
  599.       (XGrabKeyboard (dpy, fs_win, True, GrabModeAsync,
  600.               GrabModeAsync, CurrentTime) == GrabSuccess) &&
  601. #ifndef HAVE_XRANDR
  602.   //xf86vm
  603.       SwitchMode (&fs_mode, &wm_mode, true, 0, 0))
  604. #else
  605.   // xrandr
  606.       SwitchRes (&fs_scn_cfg, &wm_scn_cfg))
  607. #endif
  608. */
  609.  
  610.   if ((test1 == GrabSuccess) && (test2 == GrabSuccess) && test3)
  611.   {
  612.     full_screen = true;
  613.  
  614.     XReparentWindow (dpy, ctx_win, fs_win, 0, 0);
  615.     XWarpPointer (dpy, None, ctx_win,
  616.           0, 0, 0, 0,
  617. #ifndef HAVE_XRANDR
  618.           fs_mode.hdisplay >> 1,
  619.           fs_mode.vdisplay >> 1);
  620.  
  621.     width = fs_mode.hdisplay;
  622.     height = fs_mode.vdisplay;
  623. #else
  624.                   fs_scn_cfg.width >> 1,
  625.                   fs_scn_cfg.height >> 1);
  626.  
  627.     width = fs_scn_cfg.width;
  628.     height = fs_scn_cfg.height;
  629. #endif
  630.  
  631.     Report (CS_REPORTER_SEVERITY_NOTIFY, "FULL SCREEN: %d, %d", width, height);
  632.     XSync (dpy, False);
  633.   }
  634.   else
  635.   {
  636.     XUnmapWindow (dpy, fs_win);
  637.     Report (CS_REPORTER_SEVERITY_ERROR, "Unable to switch mode");
  638.   }
  639.  
  640.  
  641.  
  642. }
  643.  
  644. //=========================================================
  645. //    L E A V E   F U L L S C R E E N
  646. //=========================================================
  647. /*
  648.   Work in progress
  649. */
  650. void csXExtF86VM::LeaveFullScreen ()
  651. {
  652.   XWindowAttributes wa;
  653. #ifndef HAVE_XRANDR  
  654.   XF86VidModeModeInfo mode;
  655.   if (!full_screen)
  656.     return;
  657.   GetModeInfo (dpy, screen_num, &mode);
  658.   bool ret = SwitchMode (&wm_mode, &fs_mode, false, viewport_x, viewport_y);   
  659. #else
  660.   XRANDR_SCRN_CFG res_info;
  661.   if (!full_screen)
  662.     return;
  663.   GetResInfo (dpy, screen_num, &res_info);
  664.   bool ret = SwitchRes(&wm_scn_cfg, &fs_scn_cfg);
  665. #endif
  666.  
  667.   XUngrabPointer (dpy, CurrentTime);
  668.   XUngrabKeyboard (dpy, CurrentTime);
  669.  
  670.   if (!ret)
  671.   {
  672.     Report (CS_REPORTER_SEVERITY_ERROR,
  673.       "Unable to return to windowed mode....aborting\n");
  674.     exit (-1);
  675.   }
  676.  
  677.   if (wm_win != 0)
  678.   {
  679.     if (!XGetWindowAttributes (dpy, wm_win, &wa))
  680.       return;
  681.     XReparentWindow (dpy, ctx_win, wm_win, 0, 0);
  682.     width = wa.width;
  683.     height = wa.height;
  684.     XWarpPointer (dpy, None, ctx_win,
  685.           0, 0, 0, 0,
  686.           wa.width >> 1,
  687.           wa.height >> 1);
  688.   }
  689.   full_screen = false;
  690.   XUnmapWindow (dpy, fs_win);
  691.   XSync (dpy, False);
  692. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement