| Screen TutorialsTutorial: Screen events | Parent topic: Tutorial: Screen events |
The following walkthrough takes you through the process of injecting a screen event into a specified display.
screen_context_t screen_ctx; /* a connection to the screen windowing system */
screen_display_t screen_disp; /* a screen display */
screen_display_t *screen_dlist; /* a list of all available displays */
screen_event_t screen_ev; /* a screen event to handle */
int ndisplays; /* number of available displays */
int val; /* a variable used to set/get window properties */
const char *display = "1"; /* the display type */
int rval = EXIT_FAILURE; /* the application return code*/
int rc; /* a return code */
rc = screen_create_context(&screen_ctx, SCREEN_INPUT_PROVIDER_CONTEXT);
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)) {
j = atoi(display) - 1;
} 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);
This is the screen event that you will be injecting into the display.
rc = screen_create_event(&screen_ev);
In this example, you will be injecting a keyboard event.
val = SCREEN_EVENT_KEYBOARD;
rc = screen_set_event_property_iv(screen_ev, SCREEN_PROPERTY_TYPE, &val);
val = KEY_DOWN|KEY_SYM_VALID;
rc = screen_set_event_property_iv(screen_ev, SCREEN_PROPERTY_KEY_FLAGS, &val);
val = argv[i][j];
rc = screen_set_event_property_iv(screen_ev, SCREEN_PROPERTY_KEY_SYM, &val);
rc = screen_inject_event(screen_disp, screen_ev);
screen_destroy_event(screen_ev);
screen_destroy_context(screen_ctx);