|
|
1bab02 |
/*********************************************************/
|
|
|
1bab02 |
/* ptycon: a pty-console bridge */
|
|
|
f25e99 |
/* Copyright (C) 2016--2017 SysDeer Technologies, LLC */
|
|
|
1bab02 |
/* Released under GPLv2 and GPLv3; see COPYING.PTYCON. */
|
|
|
1bab02 |
/*********************************************************/
|
|
|
1bab02 |
|
|
|
1bab02 |
#include <psxtypes/psxtypes.h>
|
|
|
1bab02 |
#include <ntcon/ntcon.h>
|
|
|
1bab02 |
#include <ntapi/ntapi.h>
|
|
|
1bab02 |
#include <gdi/gdi.h>
|
|
|
1bab02 |
|
|
|
1bab02 |
#include <ptycon/ptycon.h>
|
|
|
1bab02 |
#include "ptycon_driver_impl.h"
|
|
|
1bab02 |
|
|
|
5399d4 |
int __stdcall ptyc_console_poller(struct ptyc_driver_ctx_impl * ictx)
|
|
|
1bab02 |
{
|
|
|
e73fb6 |
int32_t status;
|
|
|
e73fb6 |
int32_t iostatus;
|
|
|
e73fb6 |
struct ptyc_term_ctx * tctx;
|
|
|
6db2d7 |
struct ptyc_driver_ctx * dctx;
|
|
|
e73fb6 |
nt_tty_sigctl_info ctlinfo;
|
|
|
e73fb6 |
void * hwnd;
|
|
|
e73fb6 |
void * hevent;
|
|
|
e73fb6 |
nt_timeout timeout;
|
|
|
e73fb6 |
nt_iosb iosb;
|
|
|
e73fb6 |
gdi_rect orect;
|
|
|
e73fb6 |
gdi_rect crect;
|
|
|
e73fb6 |
int diff;
|
|
|
e73fb6 |
|
|
|
e73fb6 |
tctx = &ictx->tctx;
|
|
|
6db2d7 |
dctx = &ictx->ctx;
|
|
|
e73fb6 |
|
|
|
e73fb6 |
if (!(hwnd = ntcon->get_console_window()))
|
|
|
e73fb6 |
return NT_STATUS_INTERNAL_ERROR;
|
|
|
e73fb6 |
|
|
|
e73fb6 |
if ((status = ntapi->tt_create_private_event(
|
|
|
e73fb6 |
&hevent,
|
|
|
e73fb6 |
NT_NOTIFICATION_EVENT,
|
|
|
e73fb6 |
NT_EVENT_NOT_SIGNALED)))
|
|
|
e73fb6 |
return status;
|
|
|
e73fb6 |
|
|
|
e73fb6 |
if (!(gdi->get_client_rect(
|
|
|
e73fb6 |
hwnd,
|
|
|
e73fb6 |
&orect)))
|
|
|
e73fb6 |
return NT_STATUS_INTERNAL_ERROR;
|
|
|
e73fb6 |
|
|
|
e73fb6 |
timeout.quad = (-1) * 10 * 1000 * 50;
|
|
|
e73fb6 |
|
|
|
e73fb6 |
do {
|
|
|
e73fb6 |
status = ntapi->zw_wait_for_single_object(
|
|
|
e73fb6 |
hevent,
|
|
|
e73fb6 |
NT_SYNC_ALERTABLE,
|
|
|
e73fb6 |
&timeout);
|
|
|
e73fb6 |
|
|
|
e73fb6 |
if (!(gdi->get_client_rect(
|
|
|
e73fb6 |
hwnd,
|
|
|
e73fb6 |
&crect)))
|
|
|
e73fb6 |
return NT_STATUS_INTERNAL_ERROR;
|
|
|
e73fb6 |
|
|
|
e73fb6 |
diff = (crect.right-crect.left !=orect.right-orect.left)
|
|
|
e73fb6 |
|| (crect.bottom-crect.top !=orect.bottom-orect.top);
|
|
|
e73fb6 |
|
|
|
e73fb6 |
if (diff) {
|
|
|
e73fb6 |
orect.left = crect.left;
|
|
|
e73fb6 |
orect.right = crect.right;
|
|
|
e73fb6 |
orect.top = crect.top;
|
|
|
e73fb6 |
orect.bottom = crect.bottom;
|
|
|
e73fb6 |
|
|
|
e73fb6 |
if (!(ntcon->get_console_screen_buffer_info(
|
|
|
e73fb6 |
tctx->hout,
|
|
|
e73fb6 |
&tctx->screen_info)))
|
|
|
e73fb6 |
return NT_STATUS_INTERNAL_ERROR;
|
|
|
e73fb6 |
|
|
|
e73fb6 |
ntapi->tt_aligned_block_memset(
|
|
|
e73fb6 |
&ctlinfo,0,sizeof(ctlinfo));
|
|
|
e73fb6 |
|
|
|
e73fb6 |
ctlinfo.winsize.ws_col = tctx->screen_info.window.right
|
|
|
e73fb6 |
- tctx->screen_info.window.left
|
|
|
e73fb6 |
+ 1;
|
|
|
e73fb6 |
|
|
|
e73fb6 |
ctlinfo.winsize.ws_row = tctx->screen_info.window.bottom
|
|
|
e73fb6 |
- tctx->screen_info.window.top
|
|
|
e73fb6 |
+ 1;
|
|
|
e73fb6 |
|
|
|
e73fb6 |
if ((iostatus = ntapi->pty_ioctl(
|
|
|
e73fb6 |
ictx->cctx.hptm,
|
|
|
e73fb6 |
0,0,0,
|
|
|
e73fb6 |
&iosb,
|
|
|
e73fb6 |
TTY_TIOCSWINSZ,
|
|
|
e73fb6 |
&ctlinfo,sizeof(ctlinfo),
|
|
|
e73fb6 |
&ctlinfo,sizeof(ctlinfo))))
|
|
|
e73fb6 |
return iostatus;
|
|
|
e73fb6 |
}
|
|
|
6db2d7 |
} while ((status == NT_STATUS_TIMEOUT) && (dctx->status == NT_STATUS_SUCCESS));
|
|
|
e73fb6 |
|
|
|
6db2d7 |
return (dctx->status == NT_STATUS_PIPE_DISCONNECTED)
|
|
|
6db2d7 |
? NT_STATUS_SUCCESS
|
|
|
6db2d7 |
: dctx->status ? dctx->status : status;
|
|
|
1bab02 |
}
|