This code sample uses a privileged context to inject a Screen event into a specified display.
/*
* $QNXLicenseC:
* Copyright 2011, QNX Software Systems Limited. All Rights Reserved.
*
* This software is QNX Confidential Information subject to
* confidentiality restrictions. DISCLOSURE OF THIS SOFTWARE
* IS PROHIBITED UNLESS AUTHORIZED BY QNX SOFTWARE SYSTEMS IN
* WRITING.
*
* You must obtain a written license from and pay applicable license
* fees to QNX Software Systems Limited before you may reproduce, modify
* or distribute this software, or any work that includes all or part
* of this software. For more information visit
* http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review
* this entire file for other proprietary rights or license notices,
* as well as the QNX Development Suite License Guide at
* http://licensing.qnx.com/license-guide/ for other information.
* $
*/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <screen/screen.h>
int main(int argc, char **argv)
{
screen_context_t screen_ctx;
screen_display_t screen_disp;
screen_display_t *screen_dlist;
screen_event_t screen_ev;
int ndisplays;
int val;
const char *display = "1";
int rval = EXIT_FAILURE;
int rc;
int i, j;
for (i = 1; i < argc; i++) {
if (strncmp(argv[i], "-display=", strlen("-display=")) == 0) {
display = argv[i] + strlen("-display=");
} else {
break;
}
}
rc = screen_create_context(&screen_ctx, SCREEN_INPUT_PROVIDER_CONTEXT);
if (rc) {
perror("screen_context_create");
goto fail1;
}
rc = screen_get_context_property_iv(screen_ctx, SCREEN_PROPERTY_DISPLAY_COUNT, &ndisplays);
if (rc) {
perror("screen_get_context_property_iv(SCREEN_PROPERTY_DISPLAY_COUNT)");
goto fail2;
}
screen_dlist = calloc(ndisplays, sizeof(*screen_dlist));
if (screen_dlist == NULL) {
fprintf(stderr, "could not allocate memory for display list\n");
goto fail2;
}
rc = screen_get_context_property_pv(screen_ctx, SCREEN_PROPERTY_DISPLAYS, (void **)screen_dlist);
if (rc) {
perror("screen_get_context_property_pv(SCREEN_PROPERTY_DISPLAYS)");
free(screen_dlist);
goto fail2;
}
if (isdigit(*display)) {
int want_id = atoi(display);
for (j = 0; j < ndisplays; ++j) {
int actual_id = 0; // invalid
(void)screen_get_display_property_iv(screen_dlist[j],
SCREEN_PROPERTY_ID, &actual_id);
if (want_id == actual_id) {
break;
}
}
} else {
int type = -1;
if (strcmp(display, "internal") == 0) {
type = SCREEN_DISPLAY_TYPE_INTERNAL;
} else if (strcmp(display, "composite") == 0) {
type = SCREEN_DISPLAY_TYPE_COMPOSITE;
} else if (strcmp(display, "svideo") == 0) {
type = SCREEN_DISPLAY_TYPE_SVIDEO;
} else if (strcmp(display, "YPbPr") == 0) {
type = SCREEN_DISPLAY_TYPE_COMPONENT_YPbPr;
} else if (strcmp(display, "rgb") == 0) {
type = SCREEN_DISPLAY_TYPE_COMPONENT_RGB;
} else if (strcmp(display, "rgbhv") == 0) {
type = SCREEN_DISPLAY_TYPE_COMPONENT_RGBHV;
} else if (strcmp(display, "dvi") == 0) {
type = SCREEN_DISPLAY_TYPE_DVI;
} else if (strcmp(display, "hdmi") == 0) {
type = SCREEN_DISPLAY_TYPE_HDMI;
} else if (strcmp(display, "other") == 0) {
type = SCREEN_DISPLAY_TYPE_OTHER;
} else {
fprintf(stderr, "unknown display type %s\n", display);
free(screen_dlist);
goto fail2;
}
for (j = 0; j < ndisplays; j++) {
screen_get_display_property_iv(screen_dlist[j], SCREEN_PROPERTY_TYPE, &val);
if (val == type) {
break;
}
}
}
if (j >= ndisplays) {
fprintf(stderr, "couldn't find display %s\n", display);
free(screen_dlist);
goto fail2;
}
screen_disp = screen_dlist[j];
free(screen_dlist);
rc = screen_create_event(&screen_ev);
if (rc) {
perror("screen_create_event");
goto fail2;
}
int type = SCREEN_EVENT_MTOUCH_TOUCH;
rc = screen_set_event_property_iv(screen_ev, SCREEN_PROPERTY_TYPE, &type);
if (rc) {
perror("screen_set_event_property_iv(SCREEN_PROPERTY_TYPE)");
goto fail3;
}
int device = 10;
rc = screen_set_event_property_iv(screen_ev, SCREEN_PROPERTY_DEVICE_INDEX, &device);
if (rc) {
perror("screen_set_event_property_iv(SCREEN_PROPERTY_DEVICE_INDEX)");
goto fail3;
}
int pos[2] = { 50, 75 };
rc = screen_set_event_property_iv(screen_ev, SCREEN_PROPERTY_POSITION, pos);
if (rc) {
perror("screen_set_event_property_iv(SCREEN_PROPERTY_POSITION)");
goto fail3;
}
int seq_id = 20;
rc = screen_set_event_property_iv(screen_ev, SCREEN_PROPERTY_SEQUENCE_ID, &seq_id);
if (rc) {
perror("screen_set_event_property_iv(SCREEN_PROPERTY_SEQUENCE_ID)");
goto fail3;
}
int size[2] = { 5, 5};
rc = screen_set_event_property_iv(screen_ev, SCREEN_PROPERTY_SIZE, size);
if (rc) {
perror("screen_set_event_property_iv(SCREEN_PROPERTY_SIZE)");
goto fail3;
}
rc = screen_set_event_property_iv(screen_ev, SCREEN_PROPERTY_SOURCE_POSITION, pos);
if (rc) {
perror("screen_set_event_property_iv(SCREEN_PROPERTY_SOURCE_POSITION)");
goto fail3;
}
rc = screen_set_event_property_iv(screen_ev, SCREEN_PROPERTY_SOURCE_SIZE, &size);
if (rc) {
perror("screen_set_event_property_iv(SCREEN_PROPERTY_SOURCE_SIZE)");
goto fail3;
}
int touch_orientation = 1;
rc = screen_set_event_property_iv(screen_ev, SCREEN_PROPERTY_TOUCH_ORIENTATION, &touch_orientation);
if (rc) {
perror("screen_set_event_property_iv(SCREEN_PROPERTY_TOUCH_ORIENTATION)");
goto fail3;
}
int touchId = 3;
rc = screen_set_event_property_iv(screen_ev, SCREEN_PROPERTY_TOUCH_ID, &touchId);
if (rc) {
perror("screen_set_event_property_iv(SCREEN_PROPERTY_TOUCH_ID)");
goto fail3;
}
int touch_pressure = 1;
rc = screen_set_event_property_iv(screen_ev, SCREEN_PROPERTY_TOUCH_PRESSURE, &touch_pressure);
if (rc) {
perror("screen_set_event_property_iv(SCREEN_PROPERTY_TOUCH_PRESSURE)");
goto fail3;
}
rc = screen_inject_event(screen_disp, screen_ev);
if (rc) {
perror("screen_inject_event");
goto fail3;
}
rval = EXIT_SUCCESS;
fail3:
screen_destroy_event(screen_ev);
fail2:
screen_destroy_context(screen_ctx);
fail1:
return rval;
}