Mercurial > sdl-ios-xcode
comparison src/video/SDL_video.c @ 2875:91a7e08cd238
* Implemented X11 fullscreen input grab
* Progress towards being able to toggle in and out of fullscreen mode
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 17 Dec 2008 07:17:54 +0000 |
parents | 2fe507a2ef7d |
children | 3fcb0d447bcd |
comparison
equal
deleted
inserted
replaced
2874:36e312e0fac0 | 2875:91a7e08cd238 |
---|---|
121 }; | 121 }; |
122 | 122 |
123 static SDL_VideoDevice *_this = NULL; | 123 static SDL_VideoDevice *_this = NULL; |
124 | 124 |
125 /* Various local functions */ | 125 /* Various local functions */ |
126 int SDL_VideoInit(const char *driver_name, Uint32 flags); | 126 static void SDL_UpdateWindowGrab(SDL_Window *window); |
127 void SDL_VideoQuit(void); | |
128 | 127 |
129 static int | 128 static int |
130 cmpmodes(const void *A, const void *B) | 129 cmpmodes(const void *A, const void *B) |
131 { | 130 { |
132 SDL_DisplayMode a = *(const SDL_DisplayMode *) A; | 131 SDL_DisplayMode a = *(const SDL_DisplayMode *) A; |
633 } | 632 } |
634 /* Move any fullscreen windows into position */ | 633 /* Move any fullscreen windows into position */ |
635 for (i = 0; i < display->num_windows; ++i) { | 634 for (i = 0; i < display->num_windows; ++i) { |
636 SDL_Window *window = &display->windows[i]; | 635 SDL_Window *window = &display->windows[i]; |
637 if (FULLSCREEN_VISIBLE(window)) { | 636 if (FULLSCREEN_VISIBLE(window)) { |
638 SDL_SetWindowPosition(window->id, SDL_WINDOWPOS_CENTERED, | 637 SDL_SetWindowPosition(window->id, window->x, window->y); |
639 SDL_WINDOWPOS_CENTERED); | |
640 } | 638 } |
641 } | 639 } |
642 | 640 |
643 return 0; | 641 return 0; |
644 } | 642 } |
750 SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) | 748 SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) |
751 { | 749 { |
752 const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN | | 750 const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN | |
753 SDL_WINDOW_OPENGL | | 751 SDL_WINDOW_OPENGL | |
754 SDL_WINDOW_BORDERLESS | | 752 SDL_WINDOW_BORDERLESS | |
755 SDL_WINDOW_RESIZABLE); | 753 SDL_WINDOW_RESIZABLE | |
754 SDL_WINDOW_INPUT_GRABBED); | |
756 SDL_VideoDisplay *display; | 755 SDL_VideoDisplay *display; |
757 SDL_Window window; | 756 SDL_Window window; |
758 int num_windows; | 757 int num_windows; |
759 SDL_Window *windows; | 758 SDL_Window *windows; |
760 | 759 |
763 return 0; | 762 return 0; |
764 } | 763 } |
765 if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) { | 764 if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) { |
766 SDL_SetError("No OpenGL support in video driver"); | 765 SDL_SetError("No OpenGL support in video driver"); |
767 return 0; | 766 return 0; |
768 } | |
769 /* Fullscreen windows don't have any window decorations */ | |
770 if (flags & SDL_WINDOW_FULLSCREEN) { | |
771 flags |= SDL_WINDOW_BORDERLESS; | |
772 flags &= ~SDL_WINDOW_RESIZABLE; | |
773 } | 767 } |
774 SDL_zero(window); | 768 SDL_zero(window); |
775 window.id = _this->next_object_id++; | 769 window.id = _this->next_object_id++; |
776 window.x = x; | 770 window.x = x; |
777 window.y = y; | 771 window.y = y; |
807 SDL_MinimizeWindow(window.id); | 801 SDL_MinimizeWindow(window.id); |
808 } | 802 } |
809 if (flags & SDL_WINDOW_SHOWN) { | 803 if (flags & SDL_WINDOW_SHOWN) { |
810 SDL_ShowWindow(window.id); | 804 SDL_ShowWindow(window.id); |
811 } | 805 } |
812 if (flags & SDL_WINDOW_INPUT_GRABBED) { | 806 SDL_UpdateWindowGrab(&window); |
813 SDL_SetWindowGrab(window.id, 1); | 807 |
814 } | |
815 return window.id; | 808 return window.id; |
816 } | 809 } |
817 | 810 |
818 SDL_WindowID | 811 SDL_WindowID |
819 SDL_CreateWindowFrom(const void *data) | 812 SDL_CreateWindowFrom(const void *data) |
887 SDL_MinimizeWindow(window->id); | 880 SDL_MinimizeWindow(window->id); |
888 } | 881 } |
889 if (flags & SDL_WINDOW_SHOWN) { | 882 if (flags & SDL_WINDOW_SHOWN) { |
890 SDL_ShowWindow(window->id); | 883 SDL_ShowWindow(window->id); |
891 } | 884 } |
892 if (flags & SDL_WINDOW_INPUT_GRABBED) { | 885 SDL_UpdateWindowGrab(window); |
893 SDL_SetWindowGrab(window->id, 1); | 886 |
894 } | |
895 return 0; | 887 return 0; |
896 } | 888 } |
897 | 889 |
898 SDL_Window * | 890 SDL_Window * |
899 SDL_GetWindowFromID(SDL_WindowID windowID) | 891 SDL_GetWindowFromID(SDL_WindowID windowID) |
1002 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); | 994 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); |
1003 | 995 |
1004 if (!window) { | 996 if (!window) { |
1005 return; | 997 return; |
1006 } | 998 } |
1007 if (x == SDL_WINDOWPOS_CENTERED) { | 999 if (x != SDL_WINDOWPOS_UNDEFINED) { |
1008 window->x = (display->current_mode.w - window->w) / 2; | |
1009 } else if (x != SDL_WINDOWPOS_UNDEFINED) { | |
1010 window->x = x; | 1000 window->x = x; |
1011 } | 1001 } |
1012 if (y == SDL_WINDOWPOS_CENTERED) { | 1002 if (y != SDL_WINDOWPOS_UNDEFINED) { |
1013 window->y = (display->current_mode.h - window->h) / 2; | |
1014 } else if (y != SDL_WINDOWPOS_UNDEFINED) { | |
1015 window->y = y; | 1003 window->y = y; |
1016 } | 1004 } |
1017 if (_this->SetWindowPosition) { | 1005 if (_this->SetWindowPosition) { |
1018 _this->SetWindowPosition(_this, window); | 1006 _this->SetWindowPosition(_this, window); |
1019 } | 1007 } |
1008 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MOVED, x, y); | |
1020 } | 1009 } |
1021 | 1010 |
1022 void | 1011 void |
1023 SDL_GetWindowPosition(SDL_WindowID windowID, int *x, int *y) | 1012 SDL_GetWindowPosition(SDL_WindowID windowID, int *x, int *y) |
1024 { | 1013 { |
1080 SDL_Window *window = SDL_GetWindowFromID(windowID); | 1069 SDL_Window *window = SDL_GetWindowFromID(windowID); |
1081 | 1070 |
1082 if (!window || (window->flags & SDL_WINDOW_SHOWN)) { | 1071 if (!window || (window->flags & SDL_WINDOW_SHOWN)) { |
1083 return; | 1072 return; |
1084 } | 1073 } |
1085 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_SHOWN, 0, 0); | |
1086 | 1074 |
1087 if (_this->ShowWindow) { | 1075 if (_this->ShowWindow) { |
1088 _this->ShowWindow(_this, window); | 1076 _this->ShowWindow(_this, window); |
1089 } | 1077 } |
1078 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_SHOWN, 0, 0); | |
1090 } | 1079 } |
1091 | 1080 |
1092 void | 1081 void |
1093 SDL_HideWindow(SDL_WindowID windowID) | 1082 SDL_HideWindow(SDL_WindowID windowID) |
1094 { | 1083 { |
1095 SDL_Window *window = SDL_GetWindowFromID(windowID); | 1084 SDL_Window *window = SDL_GetWindowFromID(windowID); |
1096 | 1085 |
1097 if (!window || !(window->flags & SDL_WINDOW_SHOWN)) { | 1086 if (!window || !(window->flags & SDL_WINDOW_SHOWN)) { |
1098 return; | 1087 return; |
1099 } | 1088 } |
1100 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_HIDDEN, 0, 0); | |
1101 | 1089 |
1102 if (_this->HideWindow) { | 1090 if (_this->HideWindow) { |
1103 _this->HideWindow(_this, window); | 1091 _this->HideWindow(_this, window); |
1104 } | 1092 } |
1093 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_HIDDEN, 0, 0); | |
1105 } | 1094 } |
1106 | 1095 |
1107 void | 1096 void |
1108 SDL_RaiseWindow(SDL_WindowID windowID) | 1097 SDL_RaiseWindow(SDL_WindowID windowID) |
1109 { | 1098 { |
1123 SDL_Window *window = SDL_GetWindowFromID(windowID); | 1112 SDL_Window *window = SDL_GetWindowFromID(windowID); |
1124 | 1113 |
1125 if (!window || (window->flags & SDL_WINDOW_MAXIMIZED)) { | 1114 if (!window || (window->flags & SDL_WINDOW_MAXIMIZED)) { |
1126 return; | 1115 return; |
1127 } | 1116 } |
1128 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MAXIMIZED, 0, 0); | |
1129 | 1117 |
1130 if (_this->MaximizeWindow) { | 1118 if (_this->MaximizeWindow) { |
1131 _this->MaximizeWindow(_this, window); | 1119 _this->MaximizeWindow(_this, window); |
1132 } | 1120 } |
1121 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MAXIMIZED, 0, 0); | |
1133 } | 1122 } |
1134 | 1123 |
1135 void | 1124 void |
1136 SDL_MinimizeWindow(SDL_WindowID windowID) | 1125 SDL_MinimizeWindow(SDL_WindowID windowID) |
1137 { | 1126 { |
1138 SDL_Window *window = SDL_GetWindowFromID(windowID); | 1127 SDL_Window *window = SDL_GetWindowFromID(windowID); |
1139 | 1128 |
1140 if (!window || (window->flags & SDL_WINDOW_MINIMIZED)) { | 1129 if (!window || (window->flags & SDL_WINDOW_MINIMIZED)) { |
1141 return; | 1130 return; |
1142 } | 1131 } |
1143 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MINIMIZED, 0, 0); | |
1144 | 1132 |
1145 if (_this->MinimizeWindow) { | 1133 if (_this->MinimizeWindow) { |
1146 _this->MinimizeWindow(_this, window); | 1134 _this->MinimizeWindow(_this, window); |
1147 } | 1135 } |
1136 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MINIMIZED, 0, 0); | |
1148 } | 1137 } |
1149 | 1138 |
1150 void | 1139 void |
1151 SDL_RestoreWindow(SDL_WindowID windowID) | 1140 SDL_RestoreWindow(SDL_WindowID windowID) |
1152 { | 1141 { |
1154 | 1143 |
1155 if (!window | 1144 if (!window |
1156 || (window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) { | 1145 || (window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) { |
1157 return; | 1146 return; |
1158 } | 1147 } |
1159 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_RESTORED, 0, 0); | |
1160 | 1148 |
1161 if (_this->RestoreWindow) { | 1149 if (_this->RestoreWindow) { |
1162 _this->RestoreWindow(_this, window); | 1150 _this->RestoreWindow(_this, window); |
1163 } | 1151 } |
1152 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_RESTORED, 0, 0); | |
1164 } | 1153 } |
1165 | 1154 |
1166 int | 1155 int |
1167 SDL_SetWindowFullscreen(SDL_WindowID windowID, int fullscreen) | 1156 SDL_SetWindowFullscreen(SDL_WindowID windowID, int fullscreen) |
1168 { | 1157 { |
1215 if (mode) { | 1204 if (mode) { |
1216 window->flags |= SDL_WINDOW_INPUT_GRABBED; | 1205 window->flags |= SDL_WINDOW_INPUT_GRABBED; |
1217 } else { | 1206 } else { |
1218 window->flags &= ~SDL_WINDOW_INPUT_GRABBED; | 1207 window->flags &= ~SDL_WINDOW_INPUT_GRABBED; |
1219 } | 1208 } |
1220 | 1209 SDL_UpdateWindowGrab(window); |
1210 } | |
1211 | |
1212 static void | |
1213 SDL_UpdateWindowGrab(SDL_Window *window) | |
1214 { | |
1221 if ((window->flags & SDL_WINDOW_INPUT_FOCUS) && _this->SetWindowGrab) { | 1215 if ((window->flags & SDL_WINDOW_INPUT_FOCUS) && _this->SetWindowGrab) { |
1222 _this->SetWindowGrab(_this, window); | 1216 _this->SetWindowGrab(_this, window); |
1223 } | 1217 } |
1224 } | 1218 } |
1225 | 1219 |
1235 } | 1229 } |
1236 | 1230 |
1237 void | 1231 void |
1238 SDL_OnWindowShown(SDL_Window * window) | 1232 SDL_OnWindowShown(SDL_Window * window) |
1239 { | 1233 { |
1234 if (window->flags & SDL_WINDOW_FULLSCREEN) { | |
1235 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0); | |
1236 } | |
1240 } | 1237 } |
1241 | 1238 |
1242 void | 1239 void |
1243 SDL_OnWindowHidden(SDL_Window * window) | 1240 SDL_OnWindowHidden(SDL_Window * window) |
1244 { | 1241 { |
1242 if (window->flags & SDL_WINDOW_FULLSCREEN) { | |
1243 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0); | |
1244 } | |
1245 } | 1245 } |
1246 | 1246 |
1247 void | 1247 void |
1248 SDL_OnWindowResized(SDL_Window * window) | 1248 SDL_OnWindowResized(SDL_Window * window) |
1249 { | 1249 { |
1263 SDL_SetDisplayMode(&display->fullscreen_mode); | 1263 SDL_SetDisplayMode(&display->fullscreen_mode); |
1264 } | 1264 } |
1265 if (display->gamma && _this->SetDisplayGammaRamp) { | 1265 if (display->gamma && _this->SetDisplayGammaRamp) { |
1266 _this->SetDisplayGammaRamp(_this, display->gamma); | 1266 _this->SetDisplayGammaRamp(_this, display->gamma); |
1267 } | 1267 } |
1268 if ((window->flags & SDL_WINDOW_INPUT_GRABBED) && _this->SetWindowGrab) { | 1268 if ((window->flags & (SDL_WINDOW_INPUT_GRABBED|SDL_WINDOW_FULLSCREEN)) && _this->SetWindowGrab) { |
1269 _this->SetWindowGrab(_this, window); | 1269 _this->SetWindowGrab(_this, window); |
1270 } | 1270 } |
1271 } | 1271 } |
1272 | 1272 |
1273 void | 1273 void |
1280 SDL_SetDisplayMode(NULL); | 1280 SDL_SetDisplayMode(NULL); |
1281 } | 1281 } |
1282 if (display->gamma && _this->SetDisplayGammaRamp) { | 1282 if (display->gamma && _this->SetDisplayGammaRamp) { |
1283 _this->SetDisplayGammaRamp(_this, display->saved_gamma); | 1283 _this->SetDisplayGammaRamp(_this, display->saved_gamma); |
1284 } | 1284 } |
1285 if ((window->flags & SDL_WINDOW_INPUT_GRABBED) && _this->SetWindowGrab) { | 1285 if ((window->flags & (SDL_WINDOW_INPUT_GRABBED|SDL_WINDOW_FULLSCREEN)) && _this->SetWindowGrab) { |
1286 _this->SetWindowGrab(_this, window); | 1286 _this->SetWindowGrab(_this, window); |
1287 } | 1287 } |
1288 } | 1288 } |
1289 | 1289 |
1290 SDL_WindowID | 1290 SDL_WindowID |