diff --git a/source/app.c b/source/app.c index 259299f..3035693 100644 --- a/source/app.c +++ b/source/app.c @@ -67,12 +67,13 @@ void on_close(server_t *server, libwebsocket *socket) { app_on_close((app_t *)se -app_t *app_create(HWND window, int port, int bit_rate, int out_width, int out_height) { +app_t *app_create(HWND window, int port, int bit_rate, int out_width, int out_height, int allow_input, grabber_crop_area_t crop) { app_t *self = (app_t *)malloc(sizeof(app_t)); memset(self, 0, sizeof(app_t)); self->mouse_speed = APP_MOUSE_SPEED; - self->grabber = grabber_create(window); + self->grabber = grabber_create(window, crop); + self->allow_input = allow_input; if( !out_width ) { out_width = self->grabber->width; } if( !out_height ) { out_height = self->grabber->height; } @@ -140,6 +141,10 @@ void app_on_close(app_t *self, libwebsocket *socket) { } void app_on_message(app_t *self, libwebsocket *socket, void *data, size_t len) { + if (!self->allow_input) { + return; + } + input_type_t type = (input_type_t)((unsigned short *)data)[0]; if( type & input_type_key && len >= sizeof(input_key_t) ) { @@ -174,8 +179,8 @@ void app_on_message(app_t *self, libwebsocket *socket, void *data, size_t len) { float scale_x = ((float)self->encoder->in_width / self->encoder->out_width), scale_y =((float)self->encoder->in_height / self->encoder->out_height); - int x = (int)(input->x * scale_x + window_pos.x), - y = (int)(input->y * scale_y + window_pos.y); + int x = (int)(input->x * scale_x + window_pos.x + self->grabber->crop.x), + y = (int)(input->y * scale_y + window_pos.y + self->grabber->crop.y); //printf("mouse absolute %d, %d\n", x, y); SetCursorPos(x, y); diff --git a/source/app.h b/source/app.h index 8eb74eb..7970182 100644 --- a/source/app.h +++ b/source/app.h @@ -15,12 +15,13 @@ typedef struct { encoder_t *encoder; grabber_t *grabber; server_t *server; + int allow_input; float mouse_speed; } app_t; -app_t *app_create(HWND window, int port, int bit_rate, int out_width, int out_height); +app_t *app_create(HWND window, int port, int bit_rate, int out_width, int out_height, int allow_input, grabber_crop_area_t crop); void app_destroy(app_t *self); void app_run(app_t *self, int targt_fps); diff --git a/source/grabber.c b/source/grabber.c index 268bb8e..871cdae 100644 --- a/source/grabber.c +++ b/source/grabber.c @@ -5,7 +5,7 @@ #include "grabber.h" -grabber_t *grabber_create(HWND window) { +grabber_t *grabber_create(HWND window, grabber_crop_area_t crop) { grabber_t *self = (grabber_t *)malloc(sizeof(grabber_t)); memset(self, 0, sizeof(grabber_t)); @@ -16,6 +16,15 @@ grabber_t *grabber_create(HWND window) { self->width = rect.right-rect.left; self->height = rect.bottom-rect.top; + + self->crop = crop; + if( crop.width == 0 || crop.height == 0 ) { + self->crop.width = self->width - crop.x; + self->crop.height = self->height - crop.y; + } + + self->width = self->crop.width; + self->height = self->crop.height; self->windowDC = GetDC(window); self->memoryDC = CreateCompatibleDC(self->windowDC); @@ -47,7 +56,7 @@ void grabber_destroy(grabber_t *self) { void *grabber_grab(grabber_t *self) { SelectObject(self->memoryDC, self->bitmap); - BitBlt(self->memoryDC, 0, 0, self->width, self->height, self->windowDC, 0, 0, SRCCOPY); + BitBlt(self->memoryDC, 0, 0, self->width, self->height, self->windowDC, self->crop.x, self->crop.y, SRCCOPY); GetDIBits(self->memoryDC, self->bitmap, 0, self->height, self->pixels, (BITMAPINFO*)&(self->bitmapInfo), DIB_RGB_COLORS); return self->pixels; diff --git a/source/grabber.h b/source/grabber.h index 26e9f5f..1970996 100644 --- a/source/grabber.h +++ b/source/grabber.h @@ -4,6 +4,10 @@ #define WIN32_LEAN_AND_MEAN #include +typedef struct { + int x, y, width, height; +} grabber_crop_area_t; + typedef struct { HWND window; @@ -16,10 +20,10 @@ typedef struct { int height; void *pixels; + grabber_crop_area_t crop; } grabber_t; - -grabber_t *grabber_create(HWND window); +grabber_t *grabber_create(HWND window, grabber_crop_area_t crop); void grabber_destroy(grabber_t *self); void *grabber_grab(grabber_t *self); diff --git a/source/jsmpeg-vnc.c b/source/jsmpeg-vnc.c index 02f77f9..da2d125 100644 --- a/source/jsmpeg-vnc.c +++ b/source/jsmpeg-vnc.c @@ -32,10 +32,12 @@ void exit_usage(char *self_name) { "Usage: %s [options] \n\n" "Options:\n" - " -b bitrate in kilobit/s (default: estimated by output size)\n" - " -s output size as WxH. E.g: -s 640x480 (default: same as window size)\n" - " -f target framerate (default: 60)\n" - " -p port (default: 8080)\n\n" + " -b bitrate in kilobit/s (default: estimated by output size)\n" + " -s output size as WxH. E.g: -s 640x480 (default: same as window size)\n" + " -f target framerate (default: 60)\n" + " -p port (default: 8080)\n" + " -c crop area in the captured window as X,Y,W,H. E.g.: -c 200,300,640,480\n" + " -i enable/disable remote input. E.g. -i 0 (default: 1)\n\n" "Use \"desktop\" as the window name to capture the whole Desktop. Use \"cursor\"\n" "to capture the window at the current cursor position.\n\n" @@ -57,7 +59,10 @@ int main(int argc, char* argv[]) { fps = 60, port = 8080, width = 0, - height = 0; + height = 0, + allow_input = 1; + + grabber_crop_area_t crop = {0, 0, 0, 0}; // Parse command line options for( int i = 1; i < argc-1; i+=2 ) { @@ -70,6 +75,8 @@ int main(int argc, char* argv[]) { case 'p': port = atoi(argv[i+1]); break; case 's': sscanf(argv[i+1], "%dx%d", &width, &height); break; case 'f': fps = atoi(argv[i+1]); break; + case 'i': allow_input = atoi(argv[i+1]); break; + case 'c': sscanf(argv[i+1], "%d,%d,%d,%d", &crop.x, &crop.y, &crop.width, &crop.height); break; default: exit_usage(argv[0]); } } @@ -95,7 +102,7 @@ int main(int argc, char* argv[]) { } // Start the app - app_t *app = app_create(window, port, bit_rate, width, height); + app_t *app = app_create(window, port, bit_rate, width, height, allow_input, crop); if( !app ) { return 1;