-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1203: XWayland: XCBAtoms class r=AlanGriffiths a=wmww Move atom management into its own class, and resolve atom cookies lazily when required. Stacked on #1200 Co-authored-by: William Wold <wm@wmww.sh> (cherry picked from commit 32a6fc5)
- Loading branch information
1 parent
702fdee
commit 24b814f
Showing
5 changed files
with
251 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright (C) 2018 Marius Gripsgard <marius@ubports.com> | ||
* Copyright (C) 2020 Canonical Ltd. | ||
* | ||
* This program is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 or 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include "xcb_atoms.h" | ||
#include "boost/throw_exception.hpp" | ||
|
||
namespace mf = mir::frontend; | ||
|
||
mf::XCBAtoms::Atom::Atom(std::string const& name, Context const& context) | ||
: context{context}, | ||
name_{name}, | ||
cookie{xcb_intern_atom(context.xcb_connection, 0, name_.size(), name_.c_str())} | ||
{ | ||
} | ||
|
||
mf::XCBAtoms::Atom::operator xcb_atom_t() const | ||
{ | ||
if (!atom) | ||
{ | ||
auto const reply = xcb_intern_atom_reply(context.xcb_connection, cookie, nullptr); | ||
if (!reply) | ||
BOOST_THROW_EXCEPTION(std::runtime_error("Failed to look up atom " + name_)); | ||
atom = reply->atom; | ||
free(reply); | ||
} | ||
return atom.value(); | ||
} | ||
|
||
auto mf::XCBAtoms::Atom::name() const -> std::string | ||
{ | ||
return name_; | ||
} | ||
|
||
mf::XCBAtoms::XCBAtoms(xcb_connection_t* xcb_connection) | ||
: context{xcb_connection}, | ||
wm_protocols{"WM_PROTOCOLS", context}, | ||
wm_normal_hints{"WM_NORMAL_HINTS", context}, | ||
wm_take_focus{"WM_TAKE_FOCUS", context}, | ||
wm_delete_window{"WM_DELETE_WINDOW", context}, | ||
wm_state{"WM_STATE", context}, | ||
wm_s0{"WM_S0", context}, | ||
wm_client_machine{"WM_CLIENT_MACHINE", context}, | ||
net_wm_cm_s0{"_NET_WM_CM_S0", context}, | ||
net_wm_name{"_NET_WM_NAME", context}, | ||
net_wm_pid{"_NET_WM_PID", context}, | ||
net_wm_icon{"_NET_WM_ICON", context}, | ||
net_wm_state{"_NET_WM_STATE", context}, | ||
net_wm_state_maximized_vert{"_NET_WM_STATE_MAXIMIZED_VERT", context}, | ||
net_wm_state_maximized_horz{"_NET_WM_STATE_MAXIMIZED_HORZ", context}, | ||
net_wm_state_fullscreen{"_NET_WM_STATE_FULLSCREEN", context}, | ||
net_wm_user_time{"_NET_WM_USER_TIME", context}, | ||
net_wm_icon_name{"_NET_WM_ICON_NAME", context}, | ||
net_wm_desktop{"_NET_WM_DESKTOP", context}, | ||
net_wm_window_type{"_NET_WM_WINDOW_TYPE", context}, | ||
net_wm_window_type_desktop{"_NET_WM_WINDOW_TYPE_DESKTOP", context}, | ||
net_wm_window_type_dock{"_NET_WM_WINDOW_TYPE_DOCK", context}, | ||
net_wm_window_type_toolbar{"_NET_WM_WINDOW_TYPE_TOOLBAR", context}, | ||
net_wm_window_type_menu{"_NET_WM_WINDOW_TYPE_MENU", context}, | ||
net_wm_window_type_utility{"_NET_WM_WINDOW_TYPE_UTILITY", context}, | ||
net_wm_window_type_splash{"_NET_WM_WINDOW_TYPE_SPLASH", context}, | ||
net_wm_window_type_dialog{"_NET_WM_WINDOW_TYPE_DIALOG", context}, | ||
net_wm_window_type_dropdown{"_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", context}, | ||
net_wm_window_type_popup{"_NET_WM_WINDOW_TYPE_POPUP_MENU", context}, | ||
net_wm_window_type_tooltip{"_NET_WM_WINDOW_TYPE_TOOLTIP", context}, | ||
net_wm_window_type_notification{"_NET_WM_WINDOW_TYPE_NOTIFICATION", context}, | ||
net_wm_window_type_combo{"_NET_WM_WINDOW_TYPE_COMBO", context}, | ||
net_wm_window_type_dnd{"_NET_WM_WINDOW_TYPE_DND", context}, | ||
net_wm_window_type_normal{"_NET_WM_WINDOW_TYPE_NORMAL", context}, | ||
net_wm_moveresize{"_NET_WM_MOVERESIZE", context}, | ||
net_supporting_wm_check{"_NET_SUPPORTING_WM_CHECK", context}, | ||
net_supported{"_NET_SUPPORTED", context}, | ||
net_active_window{"_NET_ACTIVE_WINDOW", context}, | ||
motif_wm_hints{"_MOTIF_WM_HINTS", context}, | ||
clipboard{"CLIPBOARD", context}, | ||
clipboard_manager{"CLIPBOARD_MANAGER", context}, | ||
targets{"TARGETS", context}, | ||
utf8_string{"UTF8_STRING", context}, | ||
wl_selection{"_WL_SELECTION", context}, | ||
incr{"INCR", context}, | ||
timestamp{"TIMESTAMP", context}, | ||
multiple{"MULTIPLE", context}, | ||
compound_text{"COMPOUND_TEXT", context}, | ||
text{"TEXT", context}, | ||
string{"STRING", context}, | ||
window{"WINDOW", context}, | ||
text_plain_utf8{"text/plain;charset=utf-8", context}, | ||
text_plain{"text/plain", context}, | ||
xdnd_selection{"XdndSelection", context}, | ||
xdnd_aware{"XdndAware", context}, | ||
xdnd_enter{"XdndEnter", context}, | ||
xdnd_leave{"XdndLeave", context}, | ||
xdnd_drop{"XdndDrop", context}, | ||
xdnd_status{"XdndStatus", context}, | ||
xdnd_finished{"XdndFinished", context}, | ||
xdnd_type_list{"XdndTypeList", context}, | ||
xdnd_action_copy{"XdndActionCopy", context}, | ||
wl_surface_id{"WL_SURFACE_ID", context}, | ||
allow_commits{"_XWAYLAND_ALLOW_COMMITS", context} | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* Copyright (C) 2018 Marius Gripsgard <marius@ubports.com> | ||
* Copyright (C) 2020 Canonical Ltd. | ||
* | ||
* This program is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 or 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#ifndef MIR_FRONTEND_XCB_ATOMS_H | ||
#define MIR_FRONTEND_XCB_ATOMS_H | ||
|
||
#include <xcb/xcb.h> | ||
#include <string> | ||
#include <experimental/optional> | ||
|
||
namespace mir | ||
{ | ||
namespace frontend | ||
{ | ||
class XCBAtoms | ||
{ | ||
private: | ||
struct Context | ||
{ | ||
xcb_connection_t* const xcb_connection; | ||
} const context; | ||
|
||
public: | ||
XCBAtoms(xcb_connection_t* xcb_connection); | ||
|
||
class Atom | ||
{ | ||
public: | ||
/// Context should outlive the atom | ||
Atom(std::string const& name, Context const& context); | ||
operator xcb_atom_t() const; | ||
auto name() const -> std::string; | ||
|
||
private: | ||
Atom(Atom&) = delete; | ||
Atom(Atom&&) = delete; | ||
Atom& operator=(Atom&) = delete; | ||
|
||
Context const& context; | ||
std::string const name_; | ||
xcb_intern_atom_cookie_t const cookie; | ||
std::experimental::optional<xcb_atom_t> mutable atom; | ||
}; | ||
|
||
Atom const wm_protocols; | ||
Atom const wm_normal_hints; | ||
Atom const wm_take_focus; | ||
Atom const wm_delete_window; | ||
Atom const wm_state; | ||
Atom const wm_s0; | ||
Atom const wm_client_machine; | ||
Atom const net_wm_cm_s0; | ||
Atom const net_wm_name; | ||
Atom const net_wm_pid; | ||
Atom const net_wm_icon; | ||
Atom const net_wm_state; | ||
Atom const net_wm_state_maximized_vert; | ||
Atom const net_wm_state_maximized_horz; | ||
Atom const net_wm_state_fullscreen; | ||
Atom const net_wm_user_time; | ||
Atom const net_wm_icon_name; | ||
Atom const net_wm_desktop; | ||
Atom const net_wm_window_type; | ||
Atom const net_wm_window_type_desktop; | ||
Atom const net_wm_window_type_dock; | ||
Atom const net_wm_window_type_toolbar; | ||
Atom const net_wm_window_type_menu; | ||
Atom const net_wm_window_type_utility; | ||
Atom const net_wm_window_type_splash; | ||
Atom const net_wm_window_type_dialog; | ||
Atom const net_wm_window_type_dropdown; | ||
Atom const net_wm_window_type_popup; | ||
Atom const net_wm_window_type_tooltip; | ||
Atom const net_wm_window_type_notification; | ||
Atom const net_wm_window_type_combo; | ||
Atom const net_wm_window_type_dnd; | ||
Atom const net_wm_window_type_normal; | ||
Atom const net_wm_moveresize; | ||
Atom const net_supporting_wm_check; | ||
Atom const net_supported; | ||
Atom const net_active_window; | ||
Atom const motif_wm_hints; | ||
Atom const clipboard; | ||
Atom const clipboard_manager; | ||
Atom const targets; | ||
Atom const utf8_string; | ||
Atom const wl_selection; | ||
Atom const incr; | ||
Atom const timestamp; | ||
Atom const multiple; | ||
Atom const compound_text; | ||
Atom const text; | ||
Atom const string; | ||
Atom const window; | ||
Atom const text_plain_utf8; | ||
Atom const text_plain; | ||
Atom const xdnd_selection; | ||
Atom const xdnd_aware; | ||
Atom const xdnd_enter; | ||
Atom const xdnd_leave; | ||
Atom const xdnd_drop; | ||
Atom const xdnd_status; | ||
Atom const xdnd_finished; | ||
Atom const xdnd_type_list; | ||
Atom const xdnd_action_copy; | ||
Atom const wl_surface_id; | ||
Atom const allow_commits; | ||
|
||
private: | ||
XCBAtoms(XCBAtoms&) = delete; | ||
XCBAtoms(XCBAtoms&&) = delete; | ||
XCBAtoms& operator=(XCBAtoms&) = delete; | ||
}; | ||
} | ||
} | ||
|
||
#endif // MIR_FRONTEND_XCB_ATOMS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.