Commit 8b944fa7 authored by deuce's avatar deuce
Browse files

Add setname() function which sets the displayed name of the application.

The title is set at the same time.  Win32 does not differentiate between
the title and the name.
parent 8153cc94
......@@ -126,6 +126,7 @@ int try_sdl_init(int mode)
cio_api.textmode=sdl_textmode;
cio_api.showmouse=sdl_showmouse;
cio_api.hidemouse=sdl_hidemouse;
cio_api.setname=sdl_setname;
cio_api.settitle=sdl_settitle;
#ifdef _WIN32
cio_api.copytext=win32_copytext;
......@@ -161,6 +162,7 @@ int try_x_init(int mode)
cio_api.getch=x_getch;
cio_api.getche=x_getche;
cio_api.textmode=x_textmode;
cio_api.setname=x_setname;
cio_api.settitle=x_settitle;
cio_api.copytext=x_copytext;
cio_api.getcliptext=x_getcliptext;
......@@ -246,6 +248,7 @@ int try_conio_init(int mode)
cio_api.textmode=win32_textmode;
cio_api.showmouse=win32_showmouse;
cio_api.hidemouse=win32_hidemouse;
cio_api.setname=win32_settitle;
cio_api.settitle=win32_settitle;
cio_api.copytext=win32_copytext;
cio_api.getcliptext=win32_getcliptext;
......@@ -895,6 +898,13 @@ int ciolib_hidemouse(void) {
return(-1);
}
void ciolib_setname(const char *name) {
CIOLIB_INIT();
if(cio_api.setname!=NULL)
cio_api.setname(name);
}
void ciolib_settitle(const char *title) {
CIOLIB_INIT();
......
......@@ -196,6 +196,7 @@ typedef struct {
int (*hidemouse) (void);
int (*showmouse) (void);
void (*settitle) (const char *);
void (*setname) (const char *);
void (*copytext) (const char *, size_t);
char *(*getcliptext) (void);
} cioapi_t;
......@@ -244,10 +245,10 @@ void ciolib_window(int sx, int sy, int ex, int ey);
void ciolib_delline(void);
void ciolib_insline(void);
char *ciolib_getpass(const char *prompt);
void settitle(const char *title);
void ciolib_settitle(const char *title);
void ciolib_setname(const char *title);
int ciolib_showmouse(void);
int ciolib_hidemouse(void);
void ciolib_settitle(const char *title);
void ciolib_copytext(const char *text, size_t buflen);
char *ciolib_getcliptext(void);
#ifdef __cplusplus
......@@ -292,6 +293,7 @@ char *ciolib_getcliptext(void);
#define ungetmouse(a) ciolib_ungetmouse(a)
#define hidemouse() ciolib_hidemouse()
#define showmouse() ciolib_showmouse()
#define setname(a) ciolib_setname(a)
#define settitle(a) ciolib_settitle(a)
#define copytext(a,b) ciolib_copytext(a,b)
#define getcliptext() ciolib_getcliptext()
......
......@@ -134,6 +134,7 @@ char *copybuf=NULL;
char *pastebuf=NULL;
sem_t x11_beep;
sem_t x11_title;
sem_t x11_name;
int InitCS;
int InitCE;
int FW, FH;
......@@ -168,6 +169,7 @@ GC gc;
GC cgc;
int xfd;
char window_title[81];
char window_name[81];
/* X functions */
struct x11 {
......@@ -197,6 +199,7 @@ struct x11 {
int (*XChangeProperty) (Display*, Window, Atom, Atom, int, int, _Xconst unsigned char*, int);
Status (*XSendEvent) (Display*, Window, Bool, long, XEvent*);
int (*XSetSelectionOwner) (Display*, Atom, Window, Time);
int (*XSetIconName) (Display*, Window, _Xconst char *);
};
struct x11 x11;
......@@ -1115,6 +1118,8 @@ video_async_event(void *crap)
init_mode(console_new_mode);
while(!sem_trywait(&x11_beep))
x11.XBell(dpy, 0);
if(!sem_trywait(&x11_name))
x11.XSetIconName(dpy, win, window_name);
if(!sem_trywait(&x11_title))
x11.XStoreName(dpy, win, window_title);
if(!sem_trywait(&copybuf_set)) {
......@@ -1498,6 +1503,7 @@ console_init()
x11.XChangeProperty=XChangeProperty;
x11.XSendEvent=XSendEvent;
x11.XSetSelectionOwner=XSetSelectionOwner;
x11.XSetIconName=XSetIconName;
#else
#if defined(__APPLE__) && defined(__MACH__) && defined(__POWERPC__)
if((dl=dlopen("/usr/X11R6/lib/libX11.dylib",RTLD_LAZY|RTLD_GLOBAL))==NULL)
......@@ -1609,6 +1615,10 @@ console_init()
dlclose(dl);
return(-1);
}
if((x11.XSetIconName=dlsym(dl,"XSetIconName"))==NULL) {
dlclose(dl);
return(-1);
}
#endif
sem_init(&console_mode_changed,0,0);
......@@ -1617,6 +1627,7 @@ console_init()
sem_init(&pastebuf_set,0,0);
sem_init(&x11_beep,0,0);
sem_init(&x11_title,0,0);
sem_init(&x11_name,0,0);
pthread_mutex_init(&copybuf_mutex, NULL);
pthread_mutex_init(&lines_mutex, NULL);
......@@ -1739,3 +1750,9 @@ void x_win_title(const char *title)
SAFECOPY(window_title,title);
sem_post(&x11_title);
}
void x_win_name(const char *name)
{
SAFECOPY(window_name,name);
sem_post(&x11_name);
}
......@@ -76,6 +76,7 @@ struct sdl_drawchar {
enum {
SDL_USEREVENT_UPDATERECT
,SDL_USEREVENT_SETTITLE
,SDL_USEREVENT_SETNAME
,SDL_USEREVENT_SETVIDMODE
,SDL_USEREVENT_SHOWMOUSE
,SDL_USEREVENT_HIDEMOUSE
......@@ -235,6 +236,13 @@ void sdl_user_func(int func, ...)
}
SDL_mutexV(sdl_updlock);
break;
case SDL_USEREVENT_SETNAME:
if((ev.user.data1=strdup(va_arg(argptr, char *)))==NULL) {
va_end(argptr);
return;
}
while(SDL_PeepEvents(&ev, 1, SDL_ADDEVENT, 0xffffffff)!=1);
break;
case SDL_USEREVENT_SETTITLE:
if((ev.user.data1=strdup(va_arg(argptr, char *)))==NULL) {
va_end(argptr);
......@@ -780,6 +788,13 @@ void sdl_textmode(int mode)
sdl_init_mode(mode);
}
/* Called from main thread only (Passes Event) */
int sdl_setname(const char *name)
{
sdl_user_func(SDL_USEREVENT_SETNAME,name);
return(0);
}
/* Called from main thread only (Passes Event) */
int sdl_settitle(const char *title)
{
......@@ -1254,6 +1269,10 @@ int main(int argc, char **argv)
case SDL_USEREVENT_UPDATERECT:
sdl_full_screen_redraw();
break;
case SDL_USEREVENT_SETNAME:
SDL_WM_SetCaption((char *)ev.user.data1,(char *)ev.user.data1);
free(ev.user.data1);
break;
case SDL_USEREVENT_SETTITLE:
SDL_WM_SetCaption((char *)ev.user.data1,NULL);
free(ev.user.data1);
......
......@@ -29,6 +29,7 @@ int sdl_getch(void);
int sdl_getche(void);
int sdl_beep(void);
void sdl_textmode(int mode);
void sdl_setname(const char *name);
void sdl_settitle(const char *title);
int sdl_hidemouse(void);
int sdl_showmouse(void);
......
......@@ -269,6 +269,11 @@ void x_textmode(int mode)
sem_wait(&console_mode_changed);
}
void x_setname(const char *name)
{
x_win_name(name);
}
void x_settitle(const char *title)
{
x_win_title(title);
......
......@@ -54,6 +54,7 @@ int x_getch(void);
int x_getche(void);
int x_beep(void);
void x_textmode(int mode);
void x_setname(const char *name);
void x_settitle(const char *title);
void x_copytext(const char *text, size_t buflen);
char *x_getcliptext(void);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment