mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-02-28 03:27:46 +08:00
Cygwin: console: Unify EnumWindows() callback functions.
Previously, three similar callback fuctions were used in console code. This patch unifies these functions to ease maintenance cost. Fixes: 8aad3a7edeb2 ("Cygwin: console: Fix a problem that minor ID is incorrect in ConEmu.") Suggested-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
This commit is contained in:
parent
054f4801e6
commit
930e553da8
@ -69,28 +69,6 @@ exists_ntdev_silent (const device& dev)
|
|||||||
return exists_ntdev (dev) ? -1 : false;
|
return exists_ntdev (dev) ? -1 : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL CALLBACK
|
|
||||||
enum_cons_dev (HWND hw, LPARAM lp)
|
|
||||||
{
|
|
||||||
unsigned long *bitmask = (unsigned long *) lp;
|
|
||||||
HANDLE h = NULL;
|
|
||||||
fhandler_console::console_state *cs;
|
|
||||||
if ((cs = fhandler_console::open_shared_console (hw, h)))
|
|
||||||
{
|
|
||||||
*bitmask |= (1UL << cs->tty_min_state.getntty ());
|
|
||||||
UnmapViewOfFile ((void *) cs);
|
|
||||||
CloseHandle (h);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ /* Only for ConEmu */
|
|
||||||
char class_hw[32];
|
|
||||||
if (19 == GetClassName (hw, class_hw, sizeof (class_hw))
|
|
||||||
&& 0 == strcmp (class_hw, "VirtualConsoleClass"))
|
|
||||||
EnumChildWindows (hw, enum_cons_dev, lp);
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
exists_console (const device& dev)
|
exists_console (const device& dev)
|
||||||
{
|
{
|
||||||
@ -105,8 +83,7 @@ exists_console (const device& dev)
|
|||||||
default:
|
default:
|
||||||
if (dev.get_minor () < MAX_CONS_DEV)
|
if (dev.get_minor () < MAX_CONS_DEV)
|
||||||
{
|
{
|
||||||
unsigned long bitmask = 0;
|
unsigned long bitmask = fhandler_console::console_unit (-1);
|
||||||
EnumWindows (enum_cons_dev, (LPARAM) &bitmask);
|
|
||||||
return bitmask & (1UL << dev.get_minor ());
|
return bitmask & (1UL << dev.get_minor ());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -65,28 +65,6 @@ exists_ntdev_silent (const device& dev)
|
|||||||
return exists_ntdev (dev) ? -1 : false;
|
return exists_ntdev (dev) ? -1 : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL CALLBACK
|
|
||||||
enum_cons_dev (HWND hw, LPARAM lp)
|
|
||||||
{
|
|
||||||
unsigned long *bitmask = (unsigned long *) lp;
|
|
||||||
HANDLE h = NULL;
|
|
||||||
fhandler_console::console_state *cs;
|
|
||||||
if ((cs = fhandler_console::open_shared_console (hw, h)))
|
|
||||||
{
|
|
||||||
*bitmask |= (1UL << cs->tty_min_state.getntty ());
|
|
||||||
UnmapViewOfFile ((void *) cs);
|
|
||||||
CloseHandle (h);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ /* Only for ConEmu */
|
|
||||||
char class_hw[32];
|
|
||||||
if (19 == GetClassName (hw, class_hw, sizeof (class_hw))
|
|
||||||
&& 0 == strcmp (class_hw, "VirtualConsoleClass"))
|
|
||||||
EnumChildWindows (hw, enum_cons_dev, lp);
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
exists_console (const device& dev)
|
exists_console (const device& dev)
|
||||||
{
|
{
|
||||||
@ -101,8 +79,7 @@ exists_console (const device& dev)
|
|||||||
default:
|
default:
|
||||||
if (dev.get_minor () < MAX_CONS_DEV)
|
if (dev.get_minor () < MAX_CONS_DEV)
|
||||||
{
|
{
|
||||||
unsigned long bitmask = 0;
|
unsigned long bitmask = fhandler_console::console_unit (-1);
|
||||||
EnumWindows (enum_cons_dev, (LPARAM) &bitmask);
|
|
||||||
return bitmask & (1UL << dev.get_minor ());
|
return bitmask & (1UL << dev.get_minor ());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -224,49 +224,46 @@ fhandler_console::open_shared_console (HWND hw, HANDLE& h, bool& created)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
class console_unit
|
|
||||||
{
|
|
||||||
int n;
|
|
||||||
unsigned long bitmask;
|
|
||||||
HWND me;
|
|
||||||
|
|
||||||
public:
|
|
||||||
operator int () const {return n;}
|
|
||||||
console_unit (HWND);
|
|
||||||
friend BOOL CALLBACK enum_windows (HWND, LPARAM);
|
|
||||||
};
|
|
||||||
|
|
||||||
BOOL CALLBACK
|
BOOL CALLBACK
|
||||||
enum_windows (HWND hw, LPARAM lp)
|
fhandler_console::enum_windows (HWND hw, LPARAM lp)
|
||||||
{
|
{
|
||||||
console_unit *this1 = (console_unit *) lp;
|
console_unit *this1 = (console_unit *) lp;
|
||||||
if (hw == this1->me)
|
|
||||||
return TRUE;
|
|
||||||
HANDLE h = NULL;
|
HANDLE h = NULL;
|
||||||
fhandler_console::console_state *cs;
|
fhandler_console::console_state *cs;
|
||||||
if ((cs = fhandler_console::open_shared_console (hw, h)))
|
if ((cs = fhandler_console::open_shared_console (hw, h)))
|
||||||
{
|
{
|
||||||
this1->bitmask ^= 1UL << cs->tty_min_state.getntty ();
|
|
||||||
UnmapViewOfFile ((void *) cs);
|
|
||||||
CloseHandle (h);
|
CloseHandle (h);
|
||||||
|
if (major (cs->tty_min_state.getntty ()) == DEV_CONS_MAJOR)
|
||||||
|
this1->bitmask |= 1UL << minor (cs->tty_min_state.getntty ());
|
||||||
|
if (this1->n == minor (cs->tty_min_state.getntty ()))
|
||||||
|
{
|
||||||
|
this1->shared_console_info = cs;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
UnmapViewOfFile ((void *) cs);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ /* Only for ConEmu */
|
{ /* Only for ConEmu */
|
||||||
char class_hw[32];
|
char class_hw[32];
|
||||||
if (19 == GetClassName (hw, class_hw, sizeof (class_hw))
|
if (19 == GetClassName (hw, class_hw, sizeof (class_hw))
|
||||||
&& 0 == strcmp (class_hw, "VirtualConsoleClass"))
|
&& 0 == strcmp (class_hw, "VirtualConsoleClass"))
|
||||||
EnumChildWindows (hw, enum_windows, lp);
|
EnumChildWindows (hw, fhandler_console::enum_windows, lp);
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
console_unit::console_unit (HWND me0):
|
fhandler_console::console_unit::console_unit (int n0):
|
||||||
bitmask (~0UL), me (me0)
|
n (n0), bitmask (0)
|
||||||
{
|
{
|
||||||
EnumWindows (enum_windows, (LPARAM) this);
|
EnumWindows (fhandler_console::enum_windows, (LPARAM) this);
|
||||||
n = (_minor_t) ffs (bitmask) - 1;
|
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
api_fatal ("console device allocation failure - too many consoles in use, max consoles is 64");
|
n = (_minor_t) ffsl (~bitmask) - 1;
|
||||||
|
if (n < 0)
|
||||||
|
api_fatal (sizeof (bitmask) == 8 ?
|
||||||
|
"console device allocation failure - "
|
||||||
|
"too many consoles in use, max consoles is 64" :
|
||||||
|
"console device allocation failure - "
|
||||||
|
"too many consoles in use, max consoles is 32");
|
||||||
}
|
}
|
||||||
|
|
||||||
static DWORD
|
static DWORD
|
||||||
@ -640,39 +637,6 @@ skip_writeback:
|
|||||||
free (input_tmp);
|
free (input_tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct scan_console_args_t
|
|
||||||
{
|
|
||||||
_minor_t unit;
|
|
||||||
fhandler_console::console_state **shared_console_info;
|
|
||||||
};
|
|
||||||
|
|
||||||
BOOL CALLBACK
|
|
||||||
scan_console (HWND hw, LPARAM lp)
|
|
||||||
{
|
|
||||||
scan_console_args_t *p = (scan_console_args_t *) lp;
|
|
||||||
HANDLE h = NULL;
|
|
||||||
fhandler_console::console_state *cs;
|
|
||||||
if ((cs = fhandler_console::open_shared_console (hw, h)))
|
|
||||||
{
|
|
||||||
if (p->unit == minor (cs->tty_min_state.getntty ()))
|
|
||||||
{
|
|
||||||
*p->shared_console_info = cs;
|
|
||||||
CloseHandle (h);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
UnmapViewOfFile ((void *) cs);
|
|
||||||
CloseHandle (h);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ /* Only for ConEmu */
|
|
||||||
char class_hw[32];
|
|
||||||
if (19 == GetClassName (hw, class_hw, sizeof (class_hw))
|
|
||||||
&& 0 == strcmp (class_hw, "VirtualConsoleClass"))
|
|
||||||
EnumChildWindows (hw, scan_console, lp);
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
fhandler_console::set_unit ()
|
fhandler_console::set_unit ()
|
||||||
{
|
{
|
||||||
@ -696,11 +660,7 @@ fhandler_console::set_unit ()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!generic_console && (dev_t) myself->ctty != get_device ())
|
if (!generic_console && (dev_t) myself->ctty != get_device ())
|
||||||
{
|
shared_console_info[unit] = console_unit (unit);
|
||||||
/* Scan for existing shared console info */
|
|
||||||
scan_console_args_t arg = { unit, &shared_console_info[unit] };
|
|
||||||
EnumWindows (scan_console, (LPARAM) &arg);
|
|
||||||
}
|
|
||||||
if (generic_console || !shared_console_info[unit])
|
if (generic_console || !shared_console_info[unit])
|
||||||
{
|
{
|
||||||
me = GetConsoleWindow ();
|
me = GetConsoleWindow ();
|
||||||
@ -714,7 +674,7 @@ fhandler_console::set_unit ()
|
|||||||
ProtectHandleINH (cygheap->console_h);
|
ProtectHandleINH (cygheap->console_h);
|
||||||
if (created)
|
if (created)
|
||||||
{
|
{
|
||||||
unit = console_unit (me);
|
unit = console_unit (-1);
|
||||||
cs->tty_min_state.setntty (DEV_CONS_MAJOR, unit);
|
cs->tty_min_state.setntty (DEV_CONS_MAJOR, unit);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2259,6 +2259,8 @@ private:
|
|||||||
static void set_output_mode (tty::cons_mode m, const termios *t,
|
static void set_output_mode (tty::cons_mode m, const termios *t,
|
||||||
const handle_set_t *p);
|
const handle_set_t *p);
|
||||||
|
|
||||||
|
static BOOL CALLBACK enum_windows (HWND hw, LPARAM lp);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
pid_t tc_getpgid ()
|
pid_t tc_getpgid ()
|
||||||
{
|
{
|
||||||
@ -2380,6 +2382,19 @@ private:
|
|||||||
void wpbuf_send ();
|
void wpbuf_send ();
|
||||||
int fstat (struct stat *buf);
|
int fstat (struct stat *buf);
|
||||||
|
|
||||||
|
class console_unit
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
unsigned long bitmask;
|
||||||
|
console_state *shared_console_info;
|
||||||
|
public:
|
||||||
|
operator _minor_t () const {return n;}
|
||||||
|
operator console_state * () const {return shared_console_info;}
|
||||||
|
operator unsigned long () const {return bitmask;}
|
||||||
|
console_unit (int);
|
||||||
|
friend BOOL CALLBACK fhandler_console::enum_windows (HWND, LPARAM);
|
||||||
|
};
|
||||||
|
|
||||||
friend tty_min * tty_list::get_cttyp ();
|
friend tty_min * tty_list::get_cttyp ();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user