Example #1
0
void
mp_set_playstatus_by_hold_locked(media_pipe_t *mp, const char *msg)
{
  int hold = !!mp->mp_hold_flags;

  if(hold == mp->mp_hold_gate)
    return;

  mp->mp_hold_gate = hold;

  int cmd = hold ? MB_CTRL_PAUSE : MB_CTRL_PLAY;

  if(mp->mp_flags & MP_VIDEO)
    mp_send_cmd_locked(mp, &mp->mp_video, cmd);

  mp_send_cmd_locked(mp, &mp->mp_audio, cmd);

  if(!hold)
    prop_set_void(mp->mp_prop_pausereason);
  else
    prop_set_string(mp->mp_prop_pausereason, msg ?: "Paused by user");

  prop_set_string(mp->mp_prop_playstatus, hold ? "pause" : "play");

  mp_event_dispatch(mp, event_create_int(EVENT_HOLD, hold));

  if(mp->mp_flags & MP_FLUSH_ON_HOLD)
    mp_flush_locked(mp, 0);

  if(mp->mp_hold_changed != NULL)
    mp->mp_hold_changed(mp);
}
Example #2
0
static int
hc_utf8(http_connection_t *hc, const char *remain, void *opaque,
	http_cmd_t method)
{
  const char *str = http_arg_get_req(hc, "str");
  int c;
  event_t *e;

  if(str == NULL)
    return HTTP_STATUS_BAD_REQUEST;

  while((c = utf8_get(&str)) != 0) {
    switch(c) {
    case 8:
      e = event_create_action_multi(
				    (const action_type_t[]){
				      ACTION_BS, ACTION_NAV_BACK}, 2);
      break;

    default:
      e = event_create_int(EVENT_UNICODE, c);
      break;
    }
    event_to_ui(e);
  }
Example #3
0
static int
dd_read(de_dev_t *dd)
{
  struct input_event ie;
  event_t *e = NULL;
  int i;

  if(read(dd->dd_fd, &ie, 16) != 16)
    return 1;

  if(ie.type == EV_REL) {
    if(ie.code == REL_WHEEL) {
      int action = ie.value < 0 ? ACTION_DOWN : ACTION_UP;
      int cnt = abs(ie.value);
      if(cnt > 4)
	cnt = 4;

      while(cnt--) {
	e = event_create_action(action);
	event_to_ui(e);
	
      }
    }
    return 0;
  }

  if(ie.type != EV_KEY)
    return 0;

  doqual(dd, &ie, KEY_LEFTSHIFT,  QUAL_LEFT_SHIFT);
  doqual(dd, &ie, KEY_RIGHTSHIFT, QUAL_RIGHT_SHIFT);

  if(ie.value == 0)
    return 0; // release


  int shift = !!(dd->dd_qual & (QUAL_LEFT_SHIFT | QUAL_RIGHT_SHIFT));

  for(i = 0; key_to_action[i][0]; i++) {
    if(key_to_action[i][0] == ie.code) {
      event_to_ui(event_create_action(key_to_action[i][1+shift]));
      return 0;
    }
  }
  
  switch(ie.code) {
  case KEY_SPACE:
    e = event_create_int(EVENT_UNICODE, 32);
    break;

  case KEY_ENTER: 
    e = event_create_action_multi((const action_type_t[]){
	ACTION_ACTIVATE, ACTION_ENTER}, 2);
    break;
    
  case KEY_BACKSPACE:
    e = event_create_action_multi((const action_type_t[]){
	ACTION_BS, ACTION_NAV_BACK}, 2);
Example #4
0
static int
gl_keypress(glw_x11_t *gx11, XEvent *event)
{
  char str[16], c;
  KeySym keysym;
  int len;
  char buf[32];
  event_t *e = NULL;
  wchar_t wc;
  mbstate_t ps = {0};
  int n, i;
  char *s;
  action_type_t av[10];

  int state = event->xkey.state & (ShiftMask | ControlMask | Mod1Mask);

  XComposeStatus composestatus;

  if(gx11->ic != NULL) {
    len = Xutf8LookupString(gx11->ic,(XKeyPressedEvent*)event,
			    str, sizeof(str),
			    &keysym, &gx11->status);
  } else {
    len = XLookupString(&event->xkey, str, sizeof(str), 
			&keysym, &composestatus); 
  }
  
  if(len > 1) {
    buf[0] = 0;
    s = str;
    int something = 0;
    while((n = mbrtowc(&wc, s, len, &ps)) > 0) {
      strncpy(buf, s, n);
      buf[n] = '\0';
      e = event_create_int(EVENT_UNICODE, wc);

      event_to_ui(e);
      s += n;
      len -= n;
      something = 1;
    }
    return something;
  } else if((state & ~ShiftMask) == 0 && len == 1) {
    c = str[0];
    switch(c) {
      /* Static key mappings, these cannot be changed */
    case 8:          
      e = event_create_action_multi(
				    (const action_type_t[]){
				      ACTION_BS, ACTION_NAV_BACK}, 2);
      break;
    case 13:          
      e = event_create_action_multi(
				    (const action_type_t[]){
				      ACTION_ACTIVATE, ACTION_ENTER}, 2);
Example #5
0
static void
handle_btn(glw_ps3_t *gp, int pad, int code, int pressed)
{
  int16_t *store = &button_counter[pad][code];
  if(code == 0)
    return;

  if(pressed) {

    if(*store == 0 ||
       (*store > KEY_REPEAT_DELAY && (*store % KEY_REPEAT_RATE == 0))) {
      int uc = 0;
      event_t *e = NULL;

      if(code >= BTN_KEY_1 && code <= BTN_KEY_9) {
	uc = code - BTN_KEY_1 + '1';
      } else if(code == BTN_KEY_0) {
	uc = '0';
      }
      
      if(uc != 0)
	e = event_create_int(EVENT_UNICODE, uc);

      if(e == NULL) {
	const action_type_t *avec = btn_to_action[code];
	if(avec) {
	  int i = 0;
	  while(avec[i] != 0)
	    i++;
	  e = event_create_action_multi(avec, i);
	}
      }

      if(e != NULL) {
	glw_dispatch_event(&gp->gr.gr_uii, e);
	event_release(e);
      }
    }
    (*store)++;
  } else {
    *store = 0;
  }
}
Example #6
0
static void *
stdin_thread(void *aux)
{
  unsigned char c, buffer[64];
  int bufferptr = 0, r, escaped = 0;
  
  while(1) {
    event_t *e = NULL;
    
    if(escaped) {
      struct pollfd fds;
      fds.fd = 0;
      fds.events = POLLIN;
      if(poll(&fds, 1, 100) == 1)
	r = read(0, &c, 1);
      else
	r = 0;
    } else {
      r = read(0, &c, 1);
    }

    if(r == 1) {
      if(bufferptr == sizeof(buffer) - 1)
	bufferptr = 0;
	
      buffer[bufferptr++] = c;
    }
    escaped = 0;

    switch(buffer[0]) {

    case 8:
    case 0x7f:
      e = event_create_action_multi((const action_type_t[]){
	  ACTION_BS, ACTION_NAV_BACK}, 2);
      bufferptr = 0;
      break;

    case 10:
      e = event_create_action_multi((const action_type_t[]){
	  ACTION_ACTIVATE, ACTION_ENTER}, 2);
      bufferptr = 0;
      break;

    case 9:
      e = event_create_action(ACTION_FOCUS_NEXT);
      bufferptr = 0;
      break;

    case 32 ... 0x7e:
      bufferptr = 0;
      e = event_create_int(EVENT_UNICODE, buffer[0]);
      break;

    default:
      bufferptr = 0;
      break;

    case 0x1b:
      if(r == 0) {
	if(bufferptr == 1)
	  e = event_create_action(ACTION_CANCEL);
	bufferptr = 0;
      } else {
	int i;

	escaped = 1;
	buffer[bufferptr] = 0;
	
	for(i = 0; i < sizeof(map) / sizeof(map[0]); i++) {
	  if(!strcmp((const char *)map[i].codes, (const char *)buffer)) {


	    if(map[i].action) {
	      e = event_create_action(map[i].action);
	    } else if(map[i].fkey) {
	      e = event_from_Fkey(map[i].fkey, 0);
	    }
	    break;
	  }
	}

	if(e == NULL) {
#if 0
	  printf("Unmapped esc sequence: ");
	  for(i = 0; i < bufferptr; i++)
	    printf("0x%02x,", buffer[i]);
	  printf("0x00\n");
#endif
	}
      }
      break;
    }
Example #7
0
static void *
lirc_thread(void *aux)
{
  char buf[200];
  uint64_t ircode;
  uint32_t repeat;
  char keyname[100];
  int i, r, fd, len, n;
  htsbuf_queue_t q;
  struct pollfd fds;
  event_t *e;

  fd = lirc_fd;

  htsbuf_queue_init(&q, 0);
  fds.fd = fd;
  fds.events = POLLIN;

  while(1) {

    r = poll(&fds, 1, -1);
    if(r > 0) {
      if((r = read(fd, buf, sizeof(buf))) < 1) {
	TRACE(TRACE_ERROR, "lircd", "Read error: %s", strerror(errno));
	break;
      }
      htsbuf_append(&q, buf, r);
    }

    while((len = htsbuf_find(&q, 0xa)) != -1) {
      
      if(len >= sizeof(buf) - 1) {
	TRACE(TRACE_ERROR, "lircd", "Command buffer size exceeded");
	goto out;
      }

      htsbuf_read(&q, buf, len);
      buf[len] = 0;
      
      while(len > 0 && buf[len - 1] < 32)
	buf[--len] = 0;
      htsbuf_drop(&q, 1); /* Drop the \n */
      
      n = sscanf(buf, "%"PRIx64" %x %s", &ircode, &repeat, keyname);
      if(n != 3) {
	TRACE(TRACE_INFO, "lircd", "Invalid LIRC input: \"%s\"", buf);
	continue;
      }
      
      if(keyname[0] && keyname[1] == 0) {
	/* ASCII input */
	e = event_create_int(EVENT_UNICODE, keyname[0]);
      } else {
	e = NULL;
	for(i = 0; i < sizeof(lircmap) / sizeof(lircmap[0]); i++) {
	  if(!strcasecmp(keyname, lircmap[i].name)) {
	    action_type_t av[3] = {
	      lircmap[i].action1,
	      lircmap[i].action2,
	    };
	    if(av[1] != ACTION_NONE)
	      e = event_create_action_multi(av, 2);
	    else
	      e = event_create_action_multi(av, 1);
	    break;
	  }
	}
      }
      if(e == NULL) {
	snprintf(buf, sizeof(buf), "IR+%s", keyname);
	e = event_create_str(EVENT_KEYDESC, buf);
      }
      event_to_ui(e);
    }
  }
 out:
  close(fd);
  htsbuf_queue_flush(&q);
  return NULL;
}
Example #8
0
static void
handle_kb(glw_ps3_t *gp)
{
  KbInfo kbinfo;
  KbData kbdata;
  int i, j;
  int uc;
  event_t *e;
  action_type_t av[3];
  int mods;

  if(ioKbGetInfo(&kbinfo))
    return;

  for(i=0; i<MAX_KEYBOARDS; i++) {
    if(kbinfo.status[i] == 0) {
      if(gp->kb_present[i])
	TRACE(TRACE_INFO, "PS3", "Keyboard %d disconnected", i);

    } else {
      if(!gp->kb_present[i]) {

	ioKbGetConfiguration(i, &gp->kb_config[i]);

	TRACE(TRACE_INFO, "PS3",
	      "Keyboard %d connected, mapping=%d, rmode=%d, codetype=%d",
	      i, gp->kb_config[i].mapping, gp->kb_config[i].rmode,
	      gp->kb_config[i].codetype);

	ioKbSetCodeType(i, KB_CODETYPE_RAW);
      }

      if(!ioKbRead(i, &kbdata)) {
	for(j = 0; j < kbdata.nb_keycode; j++) {

	  if(0) TRACE(TRACE_DEBUG, "PS3", "Keystrike %x %x %x %x",
		      gp->kb_config[i].mapping,
		      kbdata.mkey.mkeys,
		      kbdata.led.leds,
		      kbdata.keycode[j]);

	  uc = ioKbCnvRawCode(gp->kb_config[i].mapping, kbdata.mkey,
			      kbdata.led, kbdata.keycode[j]);

	  mods = 0;
	  if(kbdata.mkey.l_shift || kbdata.mkey.r_shift)
	    mods |= KB_SHIFTMASK;
	  if(kbdata.mkey.l_alt || kbdata.mkey.r_alt)
	    mods |= KB_ALTMASK;
	  if(kbdata.mkey.l_ctrl || kbdata.mkey.r_ctrl)
	    mods |= KB_CTRLMASK;

	  for(i = 0; i < sizeof(kb2action) / sizeof(*kb2action); i++) {
	    if(kb2action[i].code == uc &&
	       (kb2action[i].modifier == -1 || kb2action[i].modifier == mods)) {

	      av[0] = kb2action[i].action1;
	      av[1] = kb2action[i].action2;
	      av[2] = kb2action[i].action3;

	      if(kb2action[i].action3 != ACTION_NONE)
		e = event_create_action_multi(av, 3);
	      else if(kb2action[i].action2 != ACTION_NONE)
		e = event_create_action_multi(av, 2);
	      else if(kb2action[i].action1 != ACTION_NONE)
		e = event_create_action_multi(av, 1);
	      else if(kb2action[i].sym != NULL) {
		char buf[128];

		snprintf(buf, sizeof(buf),
			 "%s%s%s%s",
			 mods & KB_SHIFTMASK   ? "Shift+" : "",
			 mods & KB_ALTMASK     ? "Alt+"   : "",
			 mods & KB_CTRLMASK    ? "Ctrl+"  : "",
			 kb2action[i].sym);
		e = event_create_str(EVENT_KEYDESC, buf);
	      } else {
		e = NULL;
	      }

	      if(e != NULL) {
		glw_dispatch_event(&gp->gr.gr_uii, e);
		event_release(e);
		break;
	      }
	    }
	  }

	  if(i == sizeof(kb2action) / sizeof(*kb2action) && uc < 0x8000 && uc) {
	    e = event_create_int(EVENT_UNICODE, uc);
	    glw_dispatch_event(&gp->gr.gr_uii, e);
	    event_release(e);
	  }
	}
      }
    }
    gp->kb_present[i] = kbinfo.status[i];
  }

}
Example #9
0
static void
handle_btn(glw_ps3_t *gp, int pad, int code, int pressed, int sel, int pre)
{
  if(gp->button_assign == 0) {
    // Swap X and O
    if(code == BTN_CROSS)
      code = BTN_CIRCLE;
    else if(code == BTN_CIRCLE)
      code = BTN_CROSS;
  }

  int16_t *store = &button_counter[pad][code];
  int rate = KEY_REPEAT_RATE;
  int xrep = 0;
  if(code == 0)
    return;
  
  if(pressed) {

    if(pre > 200 && *store > KEY_REPEAT_DELAY)
      xrep = 1;
    if(pre > 150)
      rate = 1;
    else if(pre > 100)
      rate = 2;

    if(*store == 0 ||
       (*store > KEY_REPEAT_DELAY && (*store % rate == 0))) {
      int uc = 0;
      event_t *e = NULL;

      if(code >= BTN_KEY_1 && code <= BTN_KEY_9) {
	uc = code - BTN_KEY_1 + '1';
      } else if(code == BTN_KEY_0) {
	uc = '0';
      }
      
      if(uc != 0)
	e = event_create_int(EVENT_UNICODE, uc);

      if(e == NULL) {
	const action_type_t *avec =
	  sel ? btn_to_action_sel[code] : btn_to_action[code];
	if(avec) {
	  int i = 0;
	  while(avec[i] != 0)
	    i++;
	  e = event_create_action_multi(avec, i);
	}
      }

      if(e != NULL) {
        e->e_flags |= EVENT_KEYPRESS;
	event_addref(e);
	event_to_ui(e);

	if(xrep) {
	  event_addref(e);
	  event_to_ui(e);
	}

	event_release(e);
      }
    }
    (*store)++;
  } else {
    *store = 0;
  }
}