Fix issue 165: MS Windows no longer opens the program window at arbitrary (wrong) position, it restores instead the last position you used.

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@810 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2009-05-20 00:11:32 +00:00
parent b9849fe8ad
commit 1b06317924
6 changed files with 79 additions and 12 deletions

View File

@ -329,4 +329,8 @@
; ;
Palette_vertical = NO; (Default NO) Palette_vertical = NO; (Default NO)
; The program remembers the last window position, if the
; OS isn't able to do it by itself. (ie: Windows)
Window_position = 9999,9999; (Default 9999,9999 which means: NA)
; end of configuration ; end of configuration

View File

@ -533,6 +533,7 @@ int Init_mode_video(int width, int height, int fullscreen, int pix_ratio)
Mouse_Y=absolute_mouse_y/Pixel_height; Mouse_Y=absolute_mouse_y/Pixel_height;
if (Mouse_Y>=Screen_height) if (Mouse_Y>=Screen_height)
Mouse_Y=Screen_height-1; Mouse_Y=Screen_height-1;
if (fullscreen)
Set_mouse_position(); Set_mouse_position();
Spare_offset_X=0; // | Il faut penser à éviter les incohérences Spare_offset_X=0; // | Il faut penser à éviter les incohérences

36
main.c
View File

@ -28,6 +28,7 @@
#include <unistd.h> #include <unistd.h>
#include <SDL.h> #include <SDL.h>
#include <SDL_image.h> #include <SDL_image.h>
#include <SDL_syswm.h>
#include "const.h" #include "const.h"
#include "struct.h" #include "struct.h"
@ -577,6 +578,22 @@ int Init_program(int argc,char * argv[])
Video_mode[starting_videomode].Fullscreen, Video_mode[starting_videomode].Fullscreen,
Pixel_ratio); Pixel_ratio);
// Windows only: move back the window to its original position.
#if defined(__WIN32__)
if (!Video_mode[starting_videomode].Fullscreen)
{
if (Config.Window_pos_x != 9999 && Config.Window_pos_y != 9999)
{
//RECT r;
static SDL_SysWMinfo pInfo;
SDL_VERSION(&pInfo.version);
SDL_GetWMInfo(&pInfo);
//GetWindowRect(pInfo.window, &r);
SetWindowPos(pInfo.window, 0, Config.Window_pos_x, Config.Window_pos_y, 0, 0, SWP_NOSIZE);
}
}
#endif
Main_image_width=Screen_width/Pixel_width; Main_image_width=Screen_width/Pixel_width;
Main_image_height=Screen_height/Pixel_height; Main_image_height=Screen_height/Pixel_height;
Spare_image_width=Screen_width/Pixel_width; Spare_image_width=Screen_width/Pixel_width;
@ -635,6 +652,25 @@ void Program_shutdown(void)
{ {
int return_code; int return_code;
// Windows only: Recover the window position.
#if defined(__WIN32__)
{
RECT r;
static SDL_SysWMinfo pInfo;
SDL_GetWMInfo(&pInfo);
GetWindowRect(pInfo.window, &r);
Config.Window_pos_x = r.left;
Config.Window_pos_y = r.top;
}
#else
// All other targets: irrelevant dimensions.
// Do not attempt to force them back on next program run.
Config.Window_pos_x = 9999;
Config.Window_pos_y = 9999;
#endif
// On libère le buffer de gestion de lignes // On libère le buffer de gestion de lignes
free(Horizontal_line_buffer); free(Horizontal_line_buffer);

View File

@ -199,6 +199,8 @@ int Load_INI_get_string(FILE * file,char * buffer,char * option_name,char * retu
int Load_INI_get_value(char * str,int * index,int * value) int Load_INI_get_value(char * str,int * index,int * value)
{ {
int negative = 0;
// On teste si la valeur actuelle est YES (ou Y): // On teste si la valeur actuelle est YES (ou Y):
if (Load_INI_seek_pattern(str+(*index),"yes,")==1) if (Load_INI_seek_pattern(str+(*index),"yes,")==1)
@ -207,28 +209,24 @@ int Load_INI_get_value(char * str,int * index,int * value)
(*index)+=4; (*index)+=4;
return 0; return 0;
} }
else
if (strcmp(str+(*index),"yes")==0) if (strcmp(str+(*index),"yes")==0)
{ {
(*value)=1; (*value)=1;
(*index)+=3; (*index)+=3;
return 0; return 0;
} }
else
if (Load_INI_seek_pattern(str+(*index),"y,")==1) if (Load_INI_seek_pattern(str+(*index),"y,")==1)
{ {
(*value)=1; (*value)=1;
(*index)+=2; (*index)+=2;
return 0; return 0;
} }
else
if (strcmp(str+(*index),"y")==0) if (strcmp(str+(*index),"y")==0)
{ {
(*value)=1; (*value)=1;
(*index)+=1; (*index)+=1;
return 0; return 0;
} }
else
// On teste si la valeur actuelle est NO (ou N): // On teste si la valeur actuelle est NO (ou N):
@ -238,28 +236,24 @@ int Load_INI_get_value(char * str,int * index,int * value)
(*index)+=3; (*index)+=3;
return 0; return 0;
} }
else
if (strcmp(str+(*index),"no")==0) if (strcmp(str+(*index),"no")==0)
{ {
(*value)=0; (*value)=0;
(*index)+=2; (*index)+=2;
return 0; return 0;
} }
else
if (Load_INI_seek_pattern(str+(*index),"n,")==1) if (Load_INI_seek_pattern(str+(*index),"n,")==1)
{ {
(*value)=0; (*value)=0;
(*index)+=2; (*index)+=2;
return 0; return 0;
} }
else
if (strcmp(str+(*index),"n")==0) if (strcmp(str+(*index),"n")==0)
{ {
(*value)=0; (*value)=0;
(*index)+=1; (*index)+=1;
return 0; return 0;
} }
else
if (str[*index]=='$') if (str[*index]=='$')
{ {
(*value)=0; (*value)=0;
@ -286,7 +280,13 @@ int Load_INI_get_value(char * str,int * index,int * value)
return ERROR_INI_CORRUPTED; return ERROR_INI_CORRUPTED;
} }
} }
else if (str[*index]=='-')
{
negative = 1;
// next character
(*index)++;
// Fall thru
}
if ((str[*index]>='0') && (str[*index]<='9')) if ((str[*index]>='0') && (str[*index]<='9'))
{ {
(*value)=0; (*value)=0;
@ -294,7 +294,15 @@ int Load_INI_get_value(char * str,int * index,int * value)
for (;;) for (;;)
{ {
if ((str[*index]>='0') && (str[*index]<='9')) if ((str[*index]>='0') && (str[*index]<='9'))
{
(*value)=((*value)*10)+str[*index]-'0'; (*value)=((*value)*10)+str[*index]-'0';
if (negative)
{
(*value)*= -1;
// This is to do it once per number.
negative = 0;
}
}
else else
if (str[*index]==',') if (str[*index]==',')
{ {
@ -772,6 +780,17 @@ int Load_INI(T_Config * conf)
goto Erreur_ERREUR_INI_CORROMPU; goto Erreur_ERREUR_INI_CORROMPU;
conf->Palette_vertical=values[0]; conf->Palette_vertical=values[0];
} }
// Optional, the window position (>98.0%)
conf->Window_pos_x=9999;
conf->Window_pos_y=9999;
if (!Load_INI_get_values (file,buffer,"Window_position",2,values))
{
conf->Window_pos_x = values[0];
conf->Window_pos_y = values[1];
}
fclose(file); fclose(file);
free(filename); free(filename);

View File

@ -630,6 +630,11 @@ int Save_INI(T_Config * conf)
if ((return_code=Save_INI_set_values (Ancien_fichier,Nouveau_fichier,buffer,"Palette_vertical",1,values,1))) if ((return_code=Save_INI_set_values (Ancien_fichier,Nouveau_fichier,buffer,"Palette_vertical",1,values,1)))
goto Erreur_Retour; goto Erreur_Retour;
values[0]=conf->Window_pos_x;
values[1]=conf->Window_pos_y;
if ((return_code=Save_INI_set_values (Ancien_fichier,Nouveau_fichier,buffer,"Window_position",2,values,0)))
goto Erreur_Retour;
Save_INI_flush(Ancien_fichier,Nouveau_fichier,buffer); Save_INI_flush(Ancien_fichier,Nouveau_fichier,buffer);

View File

@ -267,6 +267,8 @@ typedef struct
byte Default_resolution; ///< Default video mode to use on startup. Index in ::Video_mode. byte Default_resolution; ///< Default video mode to use on startup. Index in ::Video_mode.
char *Bookmark_directory[NB_BOOKMARKS];///< Bookmarked directories in fileselectors: This is the full dierctory name. char *Bookmark_directory[NB_BOOKMARKS];///< Bookmarked directories in fileselectors: This is the full dierctory name.
char Bookmark_label[NB_BOOKMARKS][8+1];///< Bookmarked directories in fileselectors: This is the displayed name. char Bookmark_label[NB_BOOKMARKS][8+1];///< Bookmarked directories in fileselectors: This is the displayed name.
int Window_pos_x; ///< Last window x position (9999 if unsupportd/irrelevant for the platform)
int Window_pos_y; ///< Last window y position (9999 if unsupportd/irrelevant for the platform)
} T_Config; } T_Config;
// Structures utilisées pour les descriptions de pages et de liste de pages. // Structures utilisées pour les descriptions de pages et de liste de pages.