/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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); }
/** * 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; }
/** * 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; }