Exemplo n.º 1
0
/**
 * Process a find_win D-Bus request.
 */
static bool
cdbus_process_find_win(session_t *ps, DBusMessage *msg) {
  const char *target = NULL;

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

  Window wid = None;

  // Find window by client window
  if (!strcmp("client", target)) {
    cdbus_window_t client = None;
    if (!cdbus_msg_get_arg(msg, 1, CDBUS_TYPE_WINDOW, &client))
      return false;
    win *w = find_toplevel(ps, client);
    if (w)
      wid = w->id;
  }
  // Find focused window
  else if (!strcmp("focused", target)) {
    win *w = find_focused(ps);
    if (w)
      wid = w->id;
  }
  else {
    printf_errf("(): " CDBUS_ERROR_BADTGT_S, target);
    cdbus_reply_err(ps, msg, CDBUS_ERROR_BADTGT, CDBUS_ERROR_BADTGT_S, target);

    return true;
  }

  cdbus_reply_wid(ps, msg, wid);

  return true;
}
Exemplo n.º 2
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; \
  }

  // 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;
}
Exemplo n.º 3
0
/**
 * Process a opts_get D-Bus request.
 */
static bool
cdbus_process_opts_get(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_get_do(tgt, apdarg_func) \
  if (!strcmp(MSTR(tgt), target)) { \
    apdarg_func(ps, msg, ps->o.tgt); \
    return true; \
  }

  // display
  if (!strcmp("display", target)) {
    cdbus_reply_string(ps, msg, DisplayString(ps->dpy));
    return true;
  }

  cdbus_m_opts_get_do(config_file, cdbus_reply_string);
  cdbus_m_opts_get_do(mark_wmwin_focused, cdbus_reply_bool);
  cdbus_m_opts_get_do(mark_ovredir_focused, cdbus_reply_bool);
  cdbus_m_opts_get_do(fork_after_register, cdbus_reply_bool);
  cdbus_m_opts_get_do(detect_rounded_corners, cdbus_reply_bool);
  cdbus_m_opts_get_do(paint_on_overlay, cdbus_reply_bool);
  cdbus_m_opts_get_do(unredir_if_possible, cdbus_reply_bool);
  cdbus_m_opts_get_do(logpath, cdbus_reply_string);
  cdbus_m_opts_get_do(synchronize, cdbus_reply_bool);

  cdbus_m_opts_get_do(refresh_rate, cdbus_reply_int32);
  cdbus_m_opts_get_do(sw_opti, cdbus_reply_bool);
  if (!strcmp("vsync", target)) {
    assert(ps->o.vsync < sizeof(VSYNC_STRS) / sizeof(VSYNC_STRS[0]));
    cdbus_reply_string(ps, msg, VSYNC_STRS[ps->o.vsync]);
    return true;
  }
  if (!strcmp("backend", target)) {
    assert(ps->o.backend < sizeof(BACKEND_STRS) / sizeof(BACKEND_STRS[0]));
    cdbus_reply_string(ps, msg, BACKEND_STRS[ps->o.backend]);
    return true;
  }
  cdbus_m_opts_get_do(dbe, cdbus_reply_bool);
  cdbus_m_opts_get_do(vsync_aggressive, cdbus_reply_bool);

  cdbus_m_opts_get_do(blur_background, cdbus_reply_bool);
  cdbus_m_opts_get_do(blur_background_frame, cdbus_reply_bool);
  cdbus_m_opts_get_do(blur_background_fixed, cdbus_reply_bool);

  cdbus_m_opts_get_do(inactive_dim, cdbus_reply_double);
  cdbus_m_opts_get_do(inactive_dim_fixed, cdbus_reply_bool);

  cdbus_m_opts_get_do(use_ewmh_active_win, cdbus_reply_bool);
  cdbus_m_opts_get_do(detect_transient, cdbus_reply_bool);
  cdbus_m_opts_get_do(detect_client_leader, cdbus_reply_bool);

#ifdef CONFIG_VSYNC_OPENGL
  cdbus_m_opts_get_do(glx_no_stencil, cdbus_reply_bool);
  cdbus_m_opts_get_do(glx_copy_from_front, cdbus_reply_bool);
  cdbus_m_opts_get_do(glx_use_copysubbuffermesa, cdbus_reply_bool);
  cdbus_m_opts_get_do(glx_no_rebind_pixmap, cdbus_reply_bool);
  cdbus_m_opts_get_do(glx_swap_method, cdbus_reply_int32);
#endif

  cdbus_m_opts_get_do(track_focus, cdbus_reply_bool);
  cdbus_m_opts_get_do(track_wdata, cdbus_reply_bool);
  cdbus_m_opts_get_do(track_leader, cdbus_reply_bool);
#undef cdbus_m_opts_get_do

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

  return true;
}
Exemplo n.º 4
0
/**
 * 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;
}
Exemplo n.º 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;
}
Exemplo n.º 6
0
/**
 * Process a opts_get D-Bus request.
 */
static bool
cdbus_process_opts_get(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_get_do(tgt, apdarg_func) \
  if (!strcmp(MSTR(tgt), target)) { \
    apdarg_func(ps, msg, ps->o.tgt); \
    return true; \
  }

  // display
  if (!strcmp("display", target)) {
    cdbus_reply_string(ps, msg, DisplayString(ps->dpy));
    return true;
  }

  cdbus_m_opts_get_do(config_file, cdbus_reply_string);
  cdbus_m_opts_get_do(mark_wmwin_focused, cdbus_reply_bool);
  cdbus_m_opts_get_do(mark_ovredir_focused, cdbus_reply_bool);
  cdbus_m_opts_get_do(fork_after_register, cdbus_reply_bool);
  cdbus_m_opts_get_do(detect_rounded_corners, cdbus_reply_bool);
  cdbus_m_opts_get_do(paint_on_overlay, cdbus_reply_bool);
  cdbus_m_opts_get_do(unredir_if_possible, cdbus_reply_bool);
  cdbus_m_opts_get_do(logpath, cdbus_reply_string);
  cdbus_m_opts_get_do(synchronize, cdbus_reply_bool);

  cdbus_m_opts_get_do(refresh_rate, cdbus_reply_int32);
  cdbus_m_opts_get_do(sw_opti, cdbus_reply_bool);
  if (!strcmp("vsync", target)) {
    assert(ps->o.vsync < sizeof(VSYNC_STRS) / sizeof(VSYNC_STRS[0]));
    cdbus_reply_string(ps, msg, VSYNC_STRS[ps->o.vsync]);
    return true;
  }
  cdbus_m_opts_get_do(dbe, cdbus_reply_bool);
  cdbus_m_opts_get_do(vsync_aggressive, cdbus_reply_bool);

  cdbus_m_opts_get_do(shadow_red, cdbus_reply_double);
  cdbus_m_opts_get_do(shadow_green, cdbus_reply_double);
  cdbus_m_opts_get_do(shadow_blue, cdbus_reply_double);
  cdbus_m_opts_get_do(shadow_radius, cdbus_reply_int32);
  cdbus_m_opts_get_do(shadow_offset_x, cdbus_reply_int32);
  cdbus_m_opts_get_do(shadow_offset_y, cdbus_reply_int32);
  cdbus_m_opts_get_do(shadow_opacity, cdbus_reply_double);
  cdbus_m_opts_get_do(clear_shadow, cdbus_reply_bool);

  cdbus_m_opts_get_do(blur_background, cdbus_reply_bool);
  cdbus_m_opts_get_do(blur_background_frame, cdbus_reply_bool);
  cdbus_m_opts_get_do(blur_background_fixed, cdbus_reply_bool);

  cdbus_m_opts_get_do(inactive_dim, cdbus_reply_double);
  cdbus_m_opts_get_do(inactive_dim_fixed, cdbus_reply_bool);

  cdbus_m_opts_get_do(use_ewmh_active_win, cdbus_reply_bool);
  cdbus_m_opts_get_do(detect_transient, cdbus_reply_bool);
  cdbus_m_opts_get_do(detect_client_leader, cdbus_reply_bool);

  cdbus_m_opts_get_do(track_focus, cdbus_reply_bool);
  cdbus_m_opts_get_do(track_wdata, cdbus_reply_bool);
  cdbus_m_opts_get_do(track_leader, cdbus_reply_bool);
#undef cdbus_m_opts_get_do

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

  return true;
}