/usr/src/castle-game-engine-4.1.1/window/unix/castlewindow_xf86vmode.inc is in castle-game-engine-src 4.1.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | {
Copyright 2001-2013 Michalis Kamburelis.
This file is part of "Castle Game Engine".
"Castle Game Engine" is free software; see the file COPYING.txt,
included in this distribution, for details about the copyright.
"Castle Game Engine" is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
----------------------------------------------------------------------------
}
{$ifdef read_interface_uses}
CastleXF86VMode,
{$endif}
{ This implements TCastleApplication video resizing with XF86VMode }
{$ifdef read_application_interface}
private
VideoModeChanged: boolean;
{ *ModeInfos are valid only if VideoModeChanged }
CurrentModeInfo, OriginalModeInfo: TXF86VidModeModeInfo;
FUseVirtualXScreen: boolean;
public
{ jezeli UseVirtualXScreen to pod X-ami zmiana rozmiarow Video przez
VideoChange nie spowoduje zmiany ScreenWidth/H i bedziemy miec
okno np. 800x600 na ekranie 640x480. To jest wlasnie virtual screen
X-ow. W sumie moze to byc fajna rzecz dla jakichs programow uzytkowych ktore
pozwalaja userowi na operowanie na ekranie jakimis kontrolkami
ale nie dla typowych pelnoekranowych gier/dem : dla nas zmiana
rozmiaru ekranu ma na celu zmniejszenie/zwiekszenie dokladnosci
renderowanego obrazu. Wiec domyslnie UseVirtualXScreen = false. }
property UseVirtualXScreen: boolean
read FUseVirtualXScreen write FUseVirtualXScreen default false;
{$endif read_application_interface}
{$ifdef read_implementation}
function XF86VidModeModeLineToModeInfo(const ModeLine: TXF86VidModeModeLine;
DotClock: Longint): TXF86VidModeModeInfo;
begin
result.dotclock := DotClock;
result.hdisplay := ModeLine.hdisplay;
result.hsyncstart := ModeLine.hsyncstart;
result.hsyncend := ModeLine.hsyncend;
result.htotal := ModeLine.htotal;
result.hskew := ModeLine.hskew;
result.vdisplay := ModeLine.vdisplay;
result.vsyncstart := ModeLine.vsyncstart;
result.vsyncend := ModeLine.vsyncend;
result.vtotal := ModeLine.vtotal;
result.flags := ModeLine.flags;
result.privsize := 0;
{ TODO: should I try to copy privsize here somehow ?
TODO: should we in TryVideoChange and VideoReset and here do something
with c_private fields ? Manual is unclear to me... }
end;
function TCastleApplication.TryVideoChange: boolean;
var
{vidModeMajorVersion, vidModeMinorVersion: integer;}
i, bestmode: integer;
modesCount: integer;
modes : PArray_PXF86VidModeModeInfo;
OriginalMode: TXF86VidModeModeLine;
OriginalModeDotClock: Longint;
{ I really don't need this, but XF86VidModeQueryExtension on my Debian
segfaults when passed nil as 2nd or 3rd param. So I pass it some valid
pointers... }
DummyEventBase: LongInt;
DummyErrorBase: LongInt;
begin
{w tej chwili nie zmieniamy BitsPerPixel ekranu wiec
robimy faktyczne VideoChange tylko jezeli VideoResize. }
if not VideoResize then exit(true);
InitializeXDisplay;
{TESTOWE:}
{ XF86VidModeQueryVersion(XDisplay, @vidModeMajorVersion,
@vidModeMinorVersion);
Writeln(Format('XF86VidModeExtension-Version %d.%d', [vidModeMajorVersion,
vidModeMinorVersion]));}
if not XF86VidModeQueryExtension(XDisplay, @DummyEventBase,
@DummyErrorBase) then
{ X server doesn't implement this extension (at least on this display) }
Exit(false);
{ if this is first VideoChange then save desktop resolution before
switching modes }
if not VideoModeChanged then
begin
XF86VidModeGetModeLine(XDisplay, XScreen, @OriginalModeDotClock,
@OriginalMode);
OriginalModeInfo := XF86VidModeModeLineToModeInfo(OriginalMode, OriginalModeDotClock);
end;
XF86VidModeGetAllModeLines(XDisplay, XScreen, @modesCount, @modes);
try
{ look for mode with requested resolution }
bestmode := -1;
for i := 0 to modesCount-1 do
if (not VideoResize) or
((modes^[i]^.hdisplay = VideoResizeWidth) and
(modes^[i]^.vdisplay = VideoResizeHeight)) then
{ TODO: jak tu dopasowac BitsPerPixel }
bestMode := i;
if bestmode < 0 then exit(false);
CurrentModeInfo := modes^[bestMode]^;
XF86VidModeSwitchToMode(XDisplay, XScreen, @CurrentModeInfo);
{SetViewport jest przydatne gdy zmienimy sie z duzego ekranu na mniejszy i
nie chcemy uzywac VirtualXScreen. Wtedy czasem nasz maly ekranik jest
nieco z boku i user musi nakierowac myszka aby byl on w srodku.
Ponizsze SetViewport zrobi to za niego. }
XF86VidModeSetViewPort(XDisplay, XScreen, 0, 0);
VideoModeChanged := true;
result := true;
finally XFree(modes) end;
end;
procedure TCastleApplication.VideoReset;
begin
if VideoModeChanged then
begin
{ switch back to original desktop resolution }
XF86VidModeSwitchToMode(XDisplay, XScreen, @OriginalModeInfo);
VideoModeChanged := false;
end;
end;
function TCastleApplication.ScreenWidth: integer;
begin
InitializeXDisplay;
{ jezeli VideoModeChanged to nie chcemy uzywac rozmiarow screenu (bo wtedy
po utworzeniu okienka fullscreen mielibysmy okno o wymiarach np. 800x600
na ekranie 640x480. Po tym oknie musielibysmy sie przewijac myszka.
Zdecydowanie, to nie jest nasz cel : zazwyczaj my zmieniajac rozdzielczosc
chcemy miec po prostu wieksza/mniejsza dokladnosc obrazu zmieniajac ilosc pixeli
na ktorych ten obraz ma sie miescic. }
if VideoModeChanged and (not UseVirtualXScreen) then
result := CurrentModeInfo.hdisplay else
result := XDisplayWidth(XDisplay, XScreen);
end;
function TCastleApplication.ScreenHeight: integer;
begin
InitializeXDisplay;
if VideoModeChanged and (not UseVirtualXScreen) then
result := CurrentModeInfo.vdisplay else
result := XDisplayHeight(XDisplay, XScreen);
end;
{$endif read_implementation}
|