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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
- Allow the use of widescreen resolutions in fullscreen mode
- Remember window size when playing in windowed mode
Peter De Wachter (pdewacht@gmail.com)
placed in the public domain
Status: submitted upstream
--- a/kodilib/src/handler/KEventHandler.cpp
+++ b/kodilib/src/handler/KEventHandler.cpp
@@ -226,86 +226,55 @@
// --------------------------------------------------------------------------------------------------------
bool KEventHandler::setScreenSize ( int width, int height, bool fullscreen )
{
- int flags = SDL_OPENGL; // | SDL_ANYFORMAT;
- if (fullscreen)
- {
- flags |= SDL_FULLSCREEN;
- }
- else
- {
- flags |= SDL_RESIZABLE;
- }
-
- if (SDL_VideoModeOK (width, height, 32, flags) == 0) // video mode not ok
- {
- if (fullscreen)
- {
- switch (width)
- {
- case 1600:
- KConsole::printf ("couldn't set video mode %dx%d:\ntrying to fallback to 1280x1024 mode", width, height);
- return setScreenSize (1280, 1024, true);
- case 1280:
- KConsole::printf ("couldn't set video mode %dx%d:\ntrying to fallback to 1024x768 mode", width, height);
- return setScreenSize (1024, 768, true);
- case 1024:
- KConsole::printf ("couldn't set video mode %dx%d:\ntrying to fallback to 800x600 mode", width, height);
- return setScreenSize (800, 600, true);
- default:
- break;
- }
-
- // fallback to window mode
- KConsole::printf ("couldn't set video mode %dx%d (%s) test failed",
- width, height,
- fullscreen ? "fullscreen" : "window");
- KConsole::printf ("trying to fallback to window mode");
- return setScreenSize (width, height, false);
- }
- else
- {
- KConsole::printError( kStringPrintf("couldn't set video mode %dx%d (window test failed)", width, height));
- return false;
- }
- }
-
- if (SDL_SetVideoMode (width, height, 32, flags) == NULL) // paranoid
+ // For fullscreen mode the requested resolution is ignore, we'll pick what
+ // SDL thinks is best.
+
+ int baseFlags = SDL_OPENGL;
+
+ if (fullscreen)
{
- if (fullscreen)
+ int flags = baseFlags | SDL_FULLSCREEN;
+ KSize fallbackSize = getScreenSize();
+
+ SDL_Rect ** modes = SDL_ListModes (NULL, flags);
+
+ if (modes != 0 && modes != (SDL_Rect **)-1)
{
- switch (width)
- {
- case 1600:
- KConsole::printf ("couldn't init video mode %dx%d:\ntrying to fallback to 1280x1024 mode", width, height);
- return setScreenSize (1280, 1024, true);
- case 1280:
- KConsole::printf ("couldn't init video mode %dx%d:\ntrying to fallback to 1024x768 mode", width, height);
- return setScreenSize (1024, 768, true);
- case 1024:
- KConsole::printf ("couldn't init video mode %dx%d:\ntrying to fallback to 800x600 mode", width, height);
- return setScreenSize (800, 600, true);
- default:
- break;
- }
-
- // fallback to window mode
- KConsole::printf ("couldn't change video mode %dx%d (fullscreen setting failed)", width, height);
- KConsole::printf ("trying to fallback to window mode");
- return setScreenSize (width, height, false);
+ for (int i = 0; modes[i]; ++i)
+ {
+ if (SDL_SetVideoMode (modes[i]->w, modes[i]->h, 0, flags) != NULL)
+ {
+ // notify interested receivers that the resolution changed
+ notification_center.notifyReceiversType(KDL_NOTIFICATION_TYPE_VIDEO_MODE_CHANGED);
+ return true;
+ }
+
+ KConsole::printf ("couldn't change vidoe mode %dx%d (fullscreen):\n%s",
+ modes[i]->w, modes[i]->h, SDL_GetError());
+ }
}
else
{
- KConsole::printError(kStringPrintf("couldn't change video mode %dx%d (%s):\n%s\n",
- width, height,
- fullscreen ? "fullscreen" : "window", SDL_GetError()), true);
- return false;
+ KConsole::printf ("SDL didn't give us a list of video modes");
}
+
+ // fallback to window mode
+ KConsole::printf ("trying to fallback to window mode");
+ width = fallbackSize.w;
+ height = fallbackSize.h;
}
- // notify interested receivers that the resolution changed
- notification_center.notifyReceiversType(KDL_NOTIFICATION_TYPE_VIDEO_MODE_CHANGED);
+ int flags = baseFlags | SDL_RESIZABLE;
+ if (SDL_SetVideoMode (width, height, 0, flags) != NULL)
+ {
+ // notify interested receivers that the resolution changed
+ notification_center.notifyReceiversType(KDL_NOTIFICATION_TYPE_VIDEO_MODE_CHANGED);
+ return true;
+ }
- return true;
+ KConsole::printError(kStringPrintf("couldn't change video mode %dx%d (window):\n%s\n",
+ width, height, SDL_GetError()), true);
+ return false;
}
// --------------------------------------------------------------------------------------------------------
@@ -332,7 +301,7 @@
return;
}
// check if resolution is restricted
- if (modes != (SDL_Rect **)-1)
+ if (modes == (SDL_Rect **)-1)
{
// all resolutions available
width = 1024;
@@ -359,7 +328,7 @@
return;
}
// check if resolution is restricted
- if (modes != (SDL_Rect **)-1)
+ if (modes == (SDL_Rect **)-1)
{
// all resolutions available
width = 1024;
--- a/py/config.py
+++ b/py/config.py
@@ -46,11 +46,14 @@
Controller.setGamma(int(value))
elif option == "fullscreen":
fullscreen = self.getboolean(section, option)
- if fullscreen <> Controller.getFullscreen():
- screen_size = self.get (section, fullscreen and "fullscreen size" or "window size")
- screen_size = tuple (map (int, screen_size.split("x")))
- Controller.changeScreenSize (screen_size[0], screen_size[1], self.getboolean(section, option))
- self.set (section, "fullscreen size", "%dx%d" % Controller.getScreenSize())
+ if fullscreen:
+ # remember window size before switching to fullscreen
+ if not Controller.getFullscreen():
+ self.set (section, "window size", "%dx%d" % Controller.getScreenSize())
+ Controller.changeScreenSize (0, 0, true)
+ else:
+ window_size = map (int, self.get (section, "window size").split("x"))
+ Controller.changeScreenSize (window_size[0], window_size[1], false)
elif section == "keyboard":
player = Controller.getPlayer()
player.setKeyForAction (value, option.replace("_", " "))
@@ -70,6 +73,10 @@
def save (self):
"""save the configuration"""
+ # Save the window size. We need to do this here as the resize
+ # notifications don't get transfered to the Python code (AFAICS).
+ if not Controller.getFullscreen():
+ self.set ("display", "window size", "%dx%d" % Controller.getScreenSize())
try:
cfg_file = file (self.config_file_path, "w+")
self.write (cfg_file)
|