示例#1
0
文件: dbus.c 项目: xorgy/companion
/**
 * Process a opts_set D-Bus request.
 */
static bool
cdbus_process_opts_set(session_t *ps, DBusMessage *msg) {
  const char *target = NULL;

  if (!cdbus_msg_get_arg(msg, 0, DBUS_TYPE_STRING, &target))
    return false;

#define cdbus_m_opts_set_do(tgt, type, real_type) \
  if (!strcmp(MSTR(tgt), target)) { \
    real_type val; \
    if (!cdbus_msg_get_arg(msg, 1, type, &val)) \
      return false; \
    ps->o.tgt = val; \
    goto cdbus_process_opts_set_success; \
  }

  // unredir_if_possible
  if (!strcmp("unredir_if_possible", target)) {
    dbus_bool_t val = FALSE;
    if (!cdbus_msg_get_arg(msg, 1, DBUS_TYPE_BOOLEAN, &val))
      return false;
    if (ps->o.unredir_if_possible != val) {
      ps->o.unredir_if_possible = val;
      ps->ev_received = true;
    }
    goto cdbus_process_opts_set_success;
  }

  // track_focus
  if (!strcmp("track_focus", target)) {
    dbus_bool_t val = FALSE;
    if (!cdbus_msg_get_arg(msg, 1, DBUS_TYPE_BOOLEAN, &val))
      return false;
    // You could enable this option, but never turn if off
    if (val) {
      opts_init_track_focus(ps);
    }
    goto cdbus_process_opts_set_success;
  }

  // vsync
  if (!strcmp("vsync", target)) {
    const char * val = NULL;
    if (!cdbus_msg_get_arg(msg, 1, DBUS_TYPE_STRING, &val))
      return false;
    if (!parse_vsync(ps, val)) {
      printf_errf("(): " CDBUS_ERROR_BADARG_S, 1, "Value invalid.");
      cdbus_reply_err(ps, msg, CDBUS_ERROR_BADARG, CDBUS_ERROR_BADARG_S, 1, "Value invalid.");
    }
    else if (!vsync_init(ps)) {
      printf_errf("(): " CDBUS_ERROR_CUSTOM_S, "Failed to initialize specified VSync method.");
      cdbus_reply_err(ps, msg, CDBUS_ERROR_CUSTOM, CDBUS_ERROR_CUSTOM_S, "Failed to initialize specified VSync method.");
    }
    else
      goto cdbus_process_opts_set_success;
    return true;
  }

#undef cdbus_m_opts_set_do

  printf_errf("(): " CDBUS_ERROR_BADTGT_S, target);
  cdbus_reply_err(ps, msg, CDBUS_ERROR_BADTGT, CDBUS_ERROR_BADTGT_S, target);

  return true;

cdbus_process_opts_set_success:
  if (!dbus_message_get_no_reply(msg))
    cdbus_reply_bool(ps, msg, true);
  return true;
}
示例#2
0
文件: dbus.c 项目: xorgy/companion
/**
 * Process a win_set D-Bus request.
 */
static bool
cdbus_process_win_set(session_t *ps, DBusMessage *msg) {
  cdbus_window_t wid = None;
  const char *target = NULL;
  DBusError err = { };

  if (!dbus_message_get_args(msg, &err,
        CDBUS_TYPE_WINDOW, &wid,
        DBUS_TYPE_STRING, &target,
        DBUS_TYPE_INVALID)) {
    printf_errf("(): Failed to parse argument of \"win_set\" (%s).",
        err.message);
    dbus_error_free(&err);
    return false;
  }

  win *w = find_win(ps, wid);

  if (!w) {
    printf_errf("(): Window %#010x not found.", wid);
    cdbus_reply_err(ps, msg, CDBUS_ERROR_BADWIN, CDBUS_ERROR_BADWIN_S, wid);
    return true;
  }

  ps->ev_received = true;

#define cdbus_m_win_set_do(tgt, type, real_type) \
  if (!strcmp(MSTR(tgt), target)) { \
    real_type val; \
    if (!cdbus_msg_get_arg(msg, 2, type, &val)) \
      return false; \
    w->tgt = val; \
    goto cdbus_process_win_set_success; \
  }

  if (!strcmp("focused_force", target)) {
    cdbus_enum_t val = UNSET;
    if (!cdbus_msg_get_arg(msg, 2, CDBUS_TYPE_ENUM, &val))
      return false;
    win_set_focused_force(ps, w, val);
    goto cdbus_process_win_set_success;
  }

  if (!strcmp("invert_color_force", target)) {
    cdbus_enum_t val = UNSET;
    if (!cdbus_msg_get_arg(msg, 2, CDBUS_TYPE_ENUM, &val))
      return false;
    win_set_invert_color_force(ps, w, val);
    goto cdbus_process_win_set_success;
  }
#undef cdbus_m_win_set_do

  printf_errf("(): " CDBUS_ERROR_BADTGT_S, target);
  cdbus_reply_err(ps, msg, CDBUS_ERROR_BADTGT, CDBUS_ERROR_BADTGT_S, target);

  return true;

cdbus_process_win_set_success:
  if (!dbus_message_get_no_reply(msg))
    cdbus_reply_bool(ps, msg, true);
  return true;
}
示例#3
0
文件: dbus.c 项目: xorgy/companion
/**
 * Process a message from D-Bus.
 */
static void
cdbus_process(session_t *ps, DBusMessage *msg) {
  bool success = false;

#define cdbus_m_ismethod(method) \
  dbus_message_is_method_call(msg, CDBUS_INTERFACE_NAME, method)

  if (cdbus_m_ismethod("reset")) {
    ps->reset = true;
    if (!dbus_message_get_no_reply(msg))
      cdbus_reply_bool(ps, msg, true);
    success = true;
  }
  else if (cdbus_m_ismethod("list_win")) {
    success = cdbus_process_list_win(ps, msg);
  }
  else if (cdbus_m_ismethod("win_get")) {
    success = cdbus_process_win_get(ps, msg);
  }
  else if (cdbus_m_ismethod("win_set")) {
    success = cdbus_process_win_set(ps, msg);
  }
  else if (cdbus_m_ismethod("find_win")) {
    success = cdbus_process_find_win(ps, msg);
  }
  else if (cdbus_m_ismethod("opts_get")) {
    success = cdbus_process_opts_get(ps, msg);
  }
  else if (cdbus_m_ismethod("opts_set")) {
    success = cdbus_process_opts_set(ps, msg);
  }
#undef cdbus_m_ismethod
  else if (dbus_message_is_method_call(msg,
        "org.freedesktop.DBus.Introspectable", "Introspect")) {
    success = cdbus_process_introspect(ps, msg);
  }
  else if (dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameAcquired")
      || dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameLost")) {
    success = true;
  }
  else {
    if (DBUS_MESSAGE_TYPE_ERROR == dbus_message_get_type(msg)) {
      printf_errf("(): Error message of path \"%s\" "
          "interface \"%s\", member \"%s\", error \"%s\"",
          dbus_message_get_path(msg), dbus_message_get_interface(msg),
          dbus_message_get_member(msg), dbus_message_get_error_name(msg));
    }
    else {
      printf_errf("(): Illegal message of type \"%s\", path \"%s\" "
          "interface \"%s\", member \"%s\"",
          cdbus_repr_msgtype(msg), dbus_message_get_path(msg),
          dbus_message_get_interface(msg), dbus_message_get_member(msg));
    }
    if (DBUS_MESSAGE_TYPE_METHOD_CALL == dbus_message_get_type(msg)
        && !dbus_message_get_no_reply(msg))
      cdbus_reply_err(ps, msg, CDBUS_ERROR_BADMSG, CDBUS_ERROR_BADMSG_S);
    success = true;
  }

  // If the message could not be processed, and an reply is expected, return
  // an empty reply.
  if (!success && DBUS_MESSAGE_TYPE_METHOD_CALL == dbus_message_get_type(msg)
      && !dbus_message_get_no_reply(msg))
    cdbus_reply_err(ps, msg, CDBUS_ERROR_UNKNOWN, CDBUS_ERROR_UNKNOWN_S);

  // Free the message
  dbus_message_unref(msg);
}
示例#4
0
文件: dbus.c 项目: xorgy/companion
/**
 * Process a win_get D-Bus request.
 */
static bool
cdbus_process_win_get(session_t *ps, DBusMessage *msg) {
  cdbus_window_t wid = None;
  const char *target = NULL;
  DBusError err = { };

  if (!dbus_message_get_args(msg, &err,
        CDBUS_TYPE_WINDOW, &wid,
        DBUS_TYPE_STRING, &target,
        DBUS_TYPE_INVALID)) {
    printf_errf("(): Failed to parse argument of \"win_get\" (%s).",
        err.message);
    dbus_error_free(&err);
    return false;
  }

  win *w = find_win(ps, wid);

  if (!w) {
    printf_errf("(): Window %#010x not found.", wid);
    cdbus_reply_err(ps, msg, CDBUS_ERROR_BADWIN, CDBUS_ERROR_BADWIN_S, wid);
    return true;
  }

#define cdbus_m_win_get_do(tgt, apdarg_func) \
  if (!strcmp(MSTR(tgt), target)) { \
    apdarg_func(ps, msg, w->tgt); \
    return true; \
  }

  cdbus_m_win_get_do(id, cdbus_reply_wid);

  // next
  if (!strcmp("next", target)) {
    cdbus_reply_wid(ps, msg, (w->next ? w->next->id: 0));
    return true;
  }

  // map_state
  if (!strcmp("map_state", target)) {
    cdbus_reply_bool(ps, msg, w->a.map_state);
    return true;
  }

  cdbus_m_win_get_do(mode, cdbus_reply_enum);
  cdbus_m_win_get_do(client_win, cdbus_reply_wid);
  cdbus_m_win_get_do(damaged, cdbus_reply_bool);
  cdbus_m_win_get_do(destroyed, cdbus_reply_bool);
  cdbus_m_win_get_do(window_type, cdbus_reply_enum);
  cdbus_m_win_get_do(wmwin, cdbus_reply_bool);
  cdbus_m_win_get_do(leader, cdbus_reply_wid);
  cdbus_m_win_get_do(focused_real, cdbus_reply_bool);
  cdbus_m_win_get_do(focused_force, cdbus_reply_enum);
  cdbus_m_win_get_do(invert_color_force, cdbus_reply_enum);
  cdbus_m_win_get_do(name, cdbus_reply_string);
  cdbus_m_win_get_do(class_instance, cdbus_reply_string);
  cdbus_m_win_get_do(class_general, cdbus_reply_string);
  cdbus_m_win_get_do(role, cdbus_reply_string);
  cdbus_m_win_get_do(opacity, cdbus_reply_uint32);
  cdbus_m_win_get_do(frame_opacity, cdbus_reply_double);
  cdbus_m_win_get_do(left_width, cdbus_reply_uint32);
  cdbus_m_win_get_do(right_width, cdbus_reply_uint32);
  cdbus_m_win_get_do(top_width, cdbus_reply_uint32);
  cdbus_m_win_get_do(bottom_width, cdbus_reply_uint32);

  cdbus_m_win_get_do(fade, cdbus_reply_bool);
  cdbus_m_win_get_do(invert_color, cdbus_reply_bool);
  cdbus_m_win_get_do(blur_background, cdbus_reply_bool);
#undef cdbus_m_win_get_do

  printf_errf("(): " CDBUS_ERROR_BADTGT_S, target);
  cdbus_reply_err(ps, msg, CDBUS_ERROR_BADTGT, CDBUS_ERROR_BADTGT_S, target);

  return true;
}
示例#5
0
/**
 * Process a opts_set D-Bus request.
 */
static bool
cdbus_process_opts_set(session_t *ps, DBusMessage *msg) {
  const char *target = NULL;

  if (!cdbus_msg_get_arg(msg, 0, DBUS_TYPE_STRING, &target))
    return false;

#define cdbus_m_opts_set_do(tgt, type, real_type) \
  if (!strcmp(MSTR(tgt), target)) { \
    real_type val; \
    if (!cdbus_msg_get_arg(msg, 1, type, &val)) \
      return false; \
    ps->o.tgt = val; \
    goto cdbus_process_opts_set_success; \
  }

  // fade_delta
  if (!strcmp("fade_delta", target)) {
    int32_t val = 0.0;
    if (!cdbus_msg_get_arg(msg, 1, DBUS_TYPE_INT32, &val))
      return false;
    ps->o.fade_delta = max_i(val, 1);
    goto cdbus_process_opts_set_success;
  }

  // fade_in_step
  if (!strcmp("fade_in_step", target)) {
    double val = 0.0;
    if (!cdbus_msg_get_arg(msg, 1, DBUS_TYPE_DOUBLE, &val))
      return false;
    ps->o.fade_in_step = normalize_d(val) * OPAQUE;
    goto cdbus_process_opts_set_success;
  }

  // fade_out_step
  if (!strcmp("fade_out_step", target)) {
    double val = 0.0;
    if (!cdbus_msg_get_arg(msg, 1, DBUS_TYPE_DOUBLE, &val))
      return false;
    ps->o.fade_out_step = normalize_d(val) * OPAQUE;
    goto cdbus_process_opts_set_success;
  }

  // no_fading_openclose
  if (!strcmp("no_fading_openclose", target)) {
    dbus_bool_t val = FALSE;
    if (!cdbus_msg_get_arg(msg, 1, DBUS_TYPE_BOOLEAN, &val))
      return false;
    opts_set_no_fading_openclose(ps, val);
    goto cdbus_process_opts_set_success;
  }

  // unredir_if_possible
  if (!strcmp("unredir_if_possible", target)) {
    dbus_bool_t val = FALSE;
    if (!cdbus_msg_get_arg(msg, 1, DBUS_TYPE_BOOLEAN, &val))
      return false;
    if (ps->o.unredir_if_possible != val) {
      ps->o.unredir_if_possible = val;
      ps->ev_received = true;
    }
    goto cdbus_process_opts_set_success;
  }

  // clear_shadow
  if (!strcmp("clear_shadow", target)) {
    dbus_bool_t val = FALSE;
    if (!cdbus_msg_get_arg(msg, 1, DBUS_TYPE_BOOLEAN, &val))
      return false;
    if (ps->o.clear_shadow != val) {
      ps->o.clear_shadow = val;
      force_repaint(ps);
    }
    goto cdbus_process_opts_set_success;
  }

  // track_focus
  if (!strcmp("track_focus", target)) {
    dbus_bool_t val = FALSE;
    if (!cdbus_msg_get_arg(msg, 1, DBUS_TYPE_BOOLEAN, &val))
      return false;
    // You could enable this option, but never turn if off
    if (val) {
      opts_init_track_focus(ps);
    }
    goto cdbus_process_opts_set_success;
  }

  // vsync
  if (!strcmp("vsync", target)) {
    const char * val = NULL;
    if (!cdbus_msg_get_arg(msg, 1, DBUS_TYPE_STRING, &val))
      return false;
    vsync_deinit(ps);
    if (!parse_vsync(ps, val)) {
      printf_errf("(): " CDBUS_ERROR_BADARG_S, 1, "Value invalid.");
      cdbus_reply_err(ps, msg, CDBUS_ERROR_BADARG, CDBUS_ERROR_BADARG_S, 1, "Value invalid.");
    }
    else if (!vsync_init(ps)) {
      printf_errf("(): " CDBUS_ERROR_CUSTOM_S, "Failed to initialize specified VSync method.");
      cdbus_reply_err(ps, msg, CDBUS_ERROR_CUSTOM, CDBUS_ERROR_CUSTOM_S, "Failed to initialize specified VSync method.");
    }
    else
      goto cdbus_process_opts_set_success;
    return true;
  }

  // redirected_force
  if (!strcmp("redirected_force", target)) {
    cdbus_enum_t val = UNSET;
    if (!cdbus_msg_get_arg(msg, 1, CDBUS_TYPE_ENUM, &val))
      return false;
    ps->o.redirected_force = val;
    force_repaint(ps);
    goto cdbus_process_opts_set_success;
  }

  // stoppaint_force
  cdbus_m_opts_set_do(stoppaint_force, CDBUS_TYPE_ENUM, cdbus_enum_t);

#undef cdbus_m_opts_set_do

  printf_errf("(): " CDBUS_ERROR_BADTGT_S, target);
  cdbus_reply_err(ps, msg, CDBUS_ERROR_BADTGT, CDBUS_ERROR_BADTGT_S, target);

  return true;

cdbus_process_opts_set_success:
  if (!dbus_message_get_no_reply(msg))
    cdbus_reply_bool(ps, msg, true);
  return true;
}