Example #1
0
static void PrintKey(SDL_keysym *sym, int pressed)
{
	/* Print the keycode, name and state */
	if ( sym->sym ) {
		printf("Key %s:  %d-%s ", pressed ?  "pressed" : "released",
					sym->sym, SDL_GetKeyName(sym->sym));
	} else {
		printf("Unknown Key (scancode = %d) %s ", sym->scancode,
					pressed ?  "pressed" : "released");
	}

	/* Print the translated character, if one exists */
	if ( sym->unicode ) {
		/* Is it a control-character? */
		if ( sym->unicode < ' ' ) {
			printf(" (^%c)", sym->unicode+'@');
		} else {
#ifdef UNICODE
			printf(" (%c)", sym->unicode);
#else
			/* This is a Latin-1 program, so only show 8-bits */
			if ( !(sym->unicode & 0xFF00) )
				printf(" (%c)", sym->unicode);
#endif
		}
	}
	print_modifiers();
	printf("\n");
}
Example #2
0
static void
PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat)
{
    char message[512];
    char *spot;
    size_t left;

    spot = message;
    left = sizeof(message);

    /* Print the keycode, name and state */
    if (sym->sym) {
        print_string(&spot, &left,
                "Key %s:  scancode %d = %s, keycode 0x%08X = %s ",
                pressed ? "pressed " : "released",
                sym->scancode,
                SDL_GetScancodeName(sym->scancode),
                sym->sym, SDL_GetKeyName(sym->sym));
    } else {
        print_string(&spot, &left,
                "Unknown Key (scancode %d = %s) %s ",
                sym->scancode,
                SDL_GetScancodeName(sym->scancode),
                pressed ? "pressed " : "released");
    }
    print_modifiers(&spot, &left);
    if (repeat) {
        print_string(&spot, &left, " (repeat)");
    }
    SDL_Log("%s\n", message);
}
Example #3
0
static void
PrintModifierState()
{
    char message[512];
    char *spot;
    size_t left;

    spot = message;
    left = sizeof(message);

    print_modifiers(&spot, &left);
    SDL_Log("Initial state:%s\n", message);
}
static void
PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat)
{
    char message[512];
    char *spot;
    size_t left;

    spot = message;
    left = sizeof(message);

    /* Print the keycode, name and state */
    if (sym->sym) {
        print_string(&spot, &left,
                "Key %s:  scancode %d = %s, keycode 0x%08X = %s ",
                pressed ? "pressed " : "released",
                sym->scancode,
                SDL_GetScancodeName(sym->scancode),
                sym->sym, SDL_GetKeyName(sym->sym));
    } else {
        print_string(&spot, &left,
                "Unknown Key (scancode %d = %s) %s ",
                sym->scancode,
                SDL_GetScancodeName(sym->scancode),
                pressed ? "pressed" : "released");
    }

    /* Print the translated character, if one exists */
    if (sym->unicode) {
        /* Is it a control-character? */
        if (sym->unicode < ' ') {
            print_string(&spot, &left, " (^%c)", sym->unicode + '@');
        } else {
#ifdef UNICODE
            print_string(&spot, &left, " (%c)", sym->unicode);
#else
            /* This is a Latin-1 program, so only show 8-bits */
            if (!(sym->unicode & 0xFF00))
                print_string(&spot, &left, " (%c)", sym->unicode);
            else
                print_string(&spot, &left, " (0x%X)", sym->unicode);
#endif
        }
    }
    print_modifiers(&spot, &left);
    if (repeat) {
        print_string(&spot, &left, " (repeat)");
    }
    SDL_Log("%s", message);
}
Example #5
0
static void input_arrived(struct uterm_input *input,
			  struct uterm_input_event *ev,
			  void *data)
{
	char s[32];

	xkb_keysym_get_name(ev->keysyms[0], s, sizeof(s));
	printf("sym %s ", s);
	if (ev->codepoints[0] != UTERM_INPUT_INVALID) {
		/*
		 * Just a proof-of-concept hack. This works because glibc uses
		 * UTF-32 (= UCS-4) as the internal wchar_t encoding.
		 */
		printf("unicode %lc ", ev->codepoints[0]);
	}
	print_modifiers(ev->mods);
}
Example #6
0
void print_compound_definition(const compound_t *compound)
{
	print_string("{\n");
	change_indent(1);

	for (entity_t const *entity = compound->members.first_entity;
	     entity != NULL; entity = entity->base.next) {
		if (entity->kind != ENTITY_COMPOUND_MEMBER)
			continue;

		print_indent();
		print_entity(entity);
		print_char('\n');
	}

	change_indent(-1);
	print_indent();
	print_char('}');
	print_modifiers(compound->modifiers);
}
Example #7
0
static void
PrintKey(SDL_keysym * sym, SDL_bool pressed, SDL_bool repeat)
{
    /* Print the keycode, name and state */
    if (sym->sym) {
        printf("Key %s:  scancode %d = %s, keycode 0x%08X = %s ",
               pressed ? "pressed " : "released",
               sym->scancode,
               SDL_GetScancodeName(sym->scancode),
               sym->sym, SDL_GetKeyName(sym->sym));
    } else {
        printf("Unknown Key (scancode %d = %s) %s ",
               sym->scancode,
               SDL_GetScancodeName(sym->scancode),
               pressed ? "pressed" : "released");
    }

    /* Print the translated character, if one exists */
    if (sym->unicode) {
        /* Is it a control-character? */
        if (sym->unicode < ' ') {
            printf(" (^%c)", sym->unicode + '@');
        } else {
#ifdef UNICODE
            printf(" (%c)", sym->unicode);
#else
            /* This is a Latin-1 program, so only show 8-bits */
            if (!(sym->unicode & 0xFF00))
                printf(" (%c)", sym->unicode);
            else
                printf(" (0x%X)", sym->unicode);
#endif
        }
    }
    print_modifiers();
    if (repeat) {
        printf(" (repeat)");
    }
    printf("\n");
}
Example #8
0
/**
 * Print the second part (the postfix) of a type.
 *
 * @param type   The type to print.
 */
static void print_function_type_post(const function_type_t *type,
                                     const scope_t *parameters)
{
	print_char('(');
	separator_t sep = { "", ", " };
	if (parameters == NULL) {
		function_parameter_t *parameter = type->parameters;
		for ( ; parameter != NULL; parameter = parameter->next) {
			print_string(sep_next(&sep));
			print_type(parameter->type);
		}
	} else {
		for (entity_t const *parameter = parameters->first_entity;
		     parameter != NULL; parameter = parameter->base.next) {
			if (parameter->kind != ENTITY_PARAMETER)
				continue;

			print_string(sep_next(&sep));
			const type_t *const param_type = parameter->declaration.type;
			if (param_type == NULL) {
				print_string(parameter->base.symbol->string);
			} else {
				print_type_ext(param_type, parameter->base.symbol, NULL);
			}
		}
	}
	if (type->variadic) {
		print_string(sep_next(&sep));
		print_string("...");
	}
	if (sep_at_first(&sep) && !type->unspecified_parameters) {
		print_string("void");
	}
	print_char(')');
	print_modifiers(type->modifiers);

	intern_print_type_post(type->return_type);
}
Example #9
0
int main () {
    xcb_connection_t    *c;
    xcb_screen_t        *screen;
    xcb_window_t        win;
    xcb_generic_event_t *e;
    uint32_t            mask = 0;
    uint32_t            values[2];

    /* Open the connection to the X server */
    c = xcb_connect( NULL, NULL );

    /* Get the first screen */
    screen = xcb_setup_roots_iterator( xcb_get_setup( c ) ).data;

    /* Ask for our window's Id */
    win = xcb_generate_id( c );

    /* Create the window */
    mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
    values[0] = screen->white_pixel;
    values[1] = XCB_EVENT_MASK_EXPOSURE         | XCB_EVENT_MASK_BUTTON_PRESS   |
                XCB_EVENT_MASK_BUTTON_RELEASE   | XCB_EVENT_MASK_POINTER_MOTION |
                XCB_EVENT_MASK_ENTER_WINDOW     | XCB_EVENT_MASK_LEAVE_WINDOW   |
                XCB_EVENT_MASK_KEY_PRESS        | XCB_EVENT_MASK_KEY_RELEASE;
    xcb_create_window(  c,                              /* connection       */
                        0,                              /* depth            */
                        win,                            /* window Id        */
                        screen->root,                   /* parent window    */
                        0, 0,                           /* x, y             */
                        150, 150,                       /* width, height    */
                        10,                             /* border_width     */
                        XCB_WINDOW_CLASS_INPUT_OUTPUT,  /* class            */
                        screen->root_visual,            /* visual           */
                        mask, values                    /* masks            */
    );

    /* Map the window on the screen */
    xcb_map_window( c, win );

    xcb_flush( c );

    while ( ( e = xcb_wait_for_event( c ) ) ) {
        switch ( e->response_type & ~0x80 ) {
            case XCB_EXPOSE: {
                xcb_expose_event_t *ev = (xcb_expose_event_t *) e;
                printf( "Window %u exposed. Region to be redrawn at location (%d,%d)\n",
                        ev->window, ev->x, ev->y, ev->width, ev->height );
                break;
            }
            case XCB_BUTTON_PRESS: {
                xcb_button_press_event_t *ev = (xcb_button_press_event_t *) e;
                print_modifiers( ev->state );
                switch ( ev->detail ) {
                    case 4:
                        printf( "Wheel Button up in window %u, at coordinates (%d,%d)\n",
                                ev->event, ev->event_x, ev->event_y );
                        break;
                    case 5:
                        printf( "Wheel Button down in window %u at coordinates (%d,%d)\n",
                                ev->event, ev->event_x, ev->event_y );
                        break;
                    default:
                        printf( "Button %d pressed in window %u, at coordinates (%d,%d)\n",
                                ev->detail, ev->event, ev->event_x, ev->event_y );
                        break;
                }
                break;
            }
            case XCB_BUTTON_RELEASE: {
                xcb_button_release_event_t *ev = (xcb_button_release_event_t *) e;
                print_modifiers( ev->state );
                printf( "Button %d released in window %u, at coordinates (%d,%d)\n",
                        ev->detail, ev->event, ev->event_x, ev->event_y );
                break;
            }
            case XCB_MOTION_NOTIFY: {
                xcb_motion_notify_event_t *ev = (xcb_motion_notify_event_t *) e;
                printf( "Mouse moved in window %u, at coordinates (%d,%d)\n",
                        ev->event, ev->event_x, ev->event_y );
                break;
            }
            case XCB_ENTER_NOTIFY: {
                xcb_enter_notify_event_t *ev = (xcb_enter_notify_event_t *) e;
                printf( "Mouse entered window %u, at coordinates (%d,%d)\n",
                        ev->event, ev->event_x, ev->event_y );
                break;
            }
            case XCB_LEAVE_NOTIFY: {
                xcb_leave_notify_event_t *ev = (xcb_leave_notify_event_t *) e;
                printf( "Mouse left window %u, at coordinates (%d,%d)\n",
                        ev->event, ev->event_x, ev->event_y );
                break;
            }
            case XCB_KEY_PRESS: {
                xcb_key_press_event_t *ev = (xcb_key_press_event_t *) e;
                print_modifiers( ev->state );
                printf( "Key %u pressed in window %u\n", ev->detail, ev->event );
                break;
            }
            case XCB_KEY_RELEASE: {
                xcb_key_release_event_t *ev = (xcb_key_release_event_t *) e;
                print_modifiers( ev->state );
                printf( "Key %u released in window %u\n", ev->detail, ev->event );
                break;
            }
            default: {
                /* Unknown event type, ignore it */
                printf( "Unknown event: %d\n", e->response_type );
                break;
            }
        }
        /* Free the Generic Event */
        free( e );
    }

    return 0;
}
Example #10
0
int main()
{
	/* Open the connection to the X server */
	xcb_connection_t *connection = xcb_connect(NULL, NULL);

	/* Get the first screen */
	xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(connection)).data;

	/* Create the window */
	xcb_window_t window = xcb_generate_id(connection);

	uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
	uint32_t values[2] = { screen->white_pixel,
		XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS |
		    XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION |
		    XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW |
		    XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE
	};

	xcb_create_window(connection, 0,			/* depth               */
			  window, screen->root,				/* parent window       */
			  0, 0,								/* x, y                */
			  150, 150,							/* width, height       */
			  10,								/* border_width        */
			  XCB_WINDOW_CLASS_INPUT_OUTPUT,	/* class               */
			  screen->root_visual,				/* visual              */
			  mask, values);					/* masks */

	/* Map the window on the screen */
	xcb_map_window(connection, window);

	xcb_flush(connection);

	xcb_generic_event_t *event;
	while ((event = xcb_wait_for_event(connection))) {
		switch (event->response_type & ~0x80) {
		case XCB_EXPOSE:{
				xcb_expose_event_t *expose = (xcb_expose_event_t *) event;

				printf("Window %"PRIu32" exposed. Region to be redrawn at location (%"PRIu16", %"PRIu16"), "
						"with dimension (%"PRIu16", %"PRIu16")\n",
						expose->window, expose->x, expose->y, expose->width, expose->height);
				break;
			} 
		case XCB_BUTTON_PRESS:{
				xcb_button_press_event_t *bp = (xcb_button_press_event_t *) event;
				print_modifiers(bp->state);

				switch (bp->detail) {
				case 4:
					printf("Wheel Button up in window %"PRIu32", at coordinates (%"PRIi16",%"PRIi16")\n",
							bp->event, bp->event_x, bp->event_y);
					break;
				case 5:
					printf("Wheel Button down in window %"PRIu32", at coordinates (%"PRIi16", %"PRIi16")\n",
							bp->event, bp->event_x, bp->event_y);
					break;
				default:
					printf("Button %"PRIu8"pressed in window %"PRIu32", at coordinates (%"PRIi16",%"PRIi16")\n",
							bp->detail, bp->event, bp->event_x, bp->event_y);
					break;
				}
				break;
			}
		case XCB_BUTTON_RELEASE:{
				xcb_button_release_event_t *br = (xcb_button_release_event_t *) event;
				print_modifiers(br->state);

				printf("Button %"PRIu8"released in window %"PRIu32", at coordinates (%"PRIi16",%"PRIi16")\n",
						br->detail, br->event, br->event_x, br->event_y);
				break;
			}
		case XCB_MOTION_NOTIFY:{
				xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *) event;

				printf("Mouse moved in window %"PRIu32", at coordinates (%"PRIi16",%"PRIi16")\n",
						motion->event, motion->event_x, motion->event_y);
				break;
			}
		case XCB_ENTER_NOTIFY:{
				xcb_enter_notify_event_t *enter = (xcb_enter_notify_event_t *) event;

				printf("Mouse entered window %"PRIu32", at coordinates (%"PRIi16",%"PRIi16")\n",
						enter->event, enter->event_x, enter->event_y);
				break;
			}
		case XCB_LEAVE_NOTIFY:{
				xcb_leave_notify_event_t *leave = (xcb_leave_notify_event_t *) event;

				printf("Mouse left window %"PRIu32", at coordinates (%"PRIi16",%"PRIi16")\n",
						leave->event, leave->event_x, leave->event_y);
				break;
			} 
		case XCB_KEY_PRESS:{
				xcb_key_press_event_t *kp = (xcb_key_press_event_t *) event;
				print_modifiers(kp->state);

				printf("Key pressed in window %"PRIu32"\n", kp->event);
				break;
			}
		case XCB_KEY_RELEASE:{
				xcb_key_release_event_t *kr = (xcb_key_release_event_t *) event;
				print_modifiers(kr->state);

				printf("Key released in window %"PRIu32"\n", kr->event);
				break;
			}
		default:
			/* Unknown event type, ignore it */
			printf("Unknown event: %"PRIu8"\n", event->response_type);
			break;
		}

		free(event);
	}

	return 0;
}