Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repurpose XCBAtoms into XCBConnection #1234

Merged
merged 7 commits into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/server/frontend_xwayland/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set(
xwayland_default_configuration.cpp
xwayland_connector.cpp xwayland_connector.h
xwayland_server.cpp xwayland_server.h
xcb_atoms.cpp xcb_atoms.h
xcb_connection.cpp xcb_connection.h
xwayland_wm.cpp xwayland_wm.h
xwayland_surface.cpp xwayland_surface.h
xwayland_surface_role.cpp xwayland_surface_role.h
Expand Down
117 changes: 0 additions & 117 deletions src/server/frontend_xwayland/xcb_atoms.cpp

This file was deleted.

127 changes: 127 additions & 0 deletions src/server/frontend_xwayland/xcb_connection.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* 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_connection.h"
#include "boost/throw_exception.hpp"

namespace mf = mir::frontend;

mf::XCBConnection::Atom::Atom(std::string const& name, XCBConnection* connection)
: connection{connection},
name_{name},
cookie{xcb_intern_atom(*connection, 0, name_.size(), name_.c_str())}
{
}

mf::XCBConnection::Atom::operator xcb_atom_t() const
{
if (!atom)
{
auto const reply = xcb_intern_atom_reply(*connection, cookie, nullptr);
if (!reply)
BOOST_THROW_EXCEPTION(std::runtime_error("Failed to look up atom " + name_));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking at how to improve the error handling here, but libxcb-errors is a little bit too involved to be rolled into this MP :)

atom = reply->atom;
free(reply);
}
return atom.value();
}

auto mf::XCBConnection::Atom::name() const -> std::string
{
return name_;
}

mf::XCBConnection::XCBConnection(int fd)
: xcb_connection{xcb_connect_to_fd(fd, nullptr)},
wm_protocols{"WM_PROTOCOLS", this},
wm_normal_hints{"WM_NORMAL_HINTS", this},
wm_take_focus{"WM_TAKE_FOCUS", this},
wm_delete_window{"WM_DELETE_WINDOW", this},
wm_state{"WM_STATE", this},
wm_change_state{"WM_CHANGE_STATE", this},
wm_s0{"WM_S0", this},
wm_client_machine{"WM_CLIENT_MACHINE", this},
net_wm_cm_s0{"_NET_WM_CM_S0", this},
net_wm_name{"_NET_WM_NAME", this},
net_wm_pid{"_NET_WM_PID", this},
net_wm_icon{"_NET_WM_ICON", this},
net_wm_state{"_NET_WM_STATE", this},
net_wm_state_maximized_vert{"_NET_WM_STATE_MAXIMIZED_VERT", this},
net_wm_state_maximized_horz{"_NET_WM_STATE_MAXIMIZED_HORZ", this},
net_wm_state_hidden{"_NET_WM_STATE_HIDDEN", this},
net_wm_state_fullscreen{"_NET_WM_STATE_FULLSCREEN", this},
net_wm_user_time{"_NET_WM_USER_TIME", this},
net_wm_icon_name{"_NET_WM_ICON_NAME", this},
net_wm_desktop{"_NET_WM_DESKTOP", this},
net_wm_window_type{"_NET_WM_WINDOW_TYPE", this},
net_wm_window_type_desktop{"_NET_WM_WINDOW_TYPE_DESKTOP", this},
net_wm_window_type_dock{"_NET_WM_WINDOW_TYPE_DOCK", this},
net_wm_window_type_toolbar{"_NET_WM_WINDOW_TYPE_TOOLBAR", this},
net_wm_window_type_menu{"_NET_WM_WINDOW_TYPE_MENU", this},
net_wm_window_type_utility{"_NET_WM_WINDOW_TYPE_UTILITY", this},
net_wm_window_type_splash{"_NET_WM_WINDOW_TYPE_SPLASH", this},
net_wm_window_type_dialog{"_NET_WM_WINDOW_TYPE_DIALOG", this},
net_wm_window_type_dropdown{"_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", this},
net_wm_window_type_popup{"_NET_WM_WINDOW_TYPE_POPUP_MENU", this},
net_wm_window_type_tooltip{"_NET_WM_WINDOW_TYPE_TOOLTIP", this},
net_wm_window_type_notification{"_NET_WM_WINDOW_TYPE_NOTIFICATION", this},
net_wm_window_type_combo{"_NET_WM_WINDOW_TYPE_COMBO", this},
net_wm_window_type_dnd{"_NET_WM_WINDOW_TYPE_DND", this},
net_wm_window_type_normal{"_NET_WM_WINDOW_TYPE_NORMAL", this},
net_wm_moveresize{"_NET_WM_MOVERESIZE", this},
net_supporting_wm_check{"_NET_SUPPORTING_WM_CHECK", this},
net_supported{"_NET_SUPPORTED", this},
net_active_window{"_NET_ACTIVE_WINDOW", this},
motif_wm_hints{"_MOTIF_WM_HINTS", this},
clipboard{"CLIPBOARD", this},
clipboard_manager{"CLIPBOARD_MANAGER", this},
targets{"TARGETS", this},
utf8_string{"UTF8_STRING", this},
wl_selection{"_WL_SELECTION", this},
incr{"INCR", this},
timestamp{"TIMESTAMP", this},
multiple{"MULTIPLE", this},
compound_text{"COMPOUND_TEXT", this},
text{"TEXT", this},
string{"STRING", this},
window{"WINDOW", this},
text_plain_utf8{"text/plain;charset=utf-8", this},
text_plain{"text/plain", this},
xdnd_selection{"XdndSelection", this},
xdnd_aware{"XdndAware", this},
xdnd_enter{"XdndEnter", this},
xdnd_leave{"XdndLeave", this},
xdnd_drop{"XdndDrop", this},
xdnd_status{"XdndStatus", this},
xdnd_finished{"XdndFinished", this},
xdnd_type_list{"XdndTypeList", this},
xdnd_action_copy{"XdndActionCopy", this},
wl_surface_id{"WL_SURFACE_ID", this},
allow_commits{"_XWAYLAND_ALLOW_COMMITS", this}
{
}

mf::XCBConnection::~XCBConnection()
{
xcb_disconnect(xcb_connection);
}

mf::XCBConnection::operator xcb_connection_t*() const
{
return xcb_connection;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*
*/

#ifndef MIR_FRONTEND_XCB_ATOMS_H
#define MIR_FRONTEND_XCB_ATOMS_H
#ifndef MIR_FRONTEND_XCB_CONNECTION_H
#define MIR_FRONTEND_XCB_CONNECTION_H

#include <xcb/xcb.h>
#include <string>
Expand All @@ -27,22 +27,27 @@ namespace mir
{
namespace frontend
{
class XCBAtoms
class XCBConnection
{
public:
explicit XCBConnection(int fd);
~XCBConnection();

operator xcb_connection_t*() const;

private:
struct Context
{
xcb_connection_t* const xcb_connection;
} const context;
XCBConnection(XCBConnection&) = delete;
XCBConnection(XCBConnection&&) = delete;
XCBConnection& operator=(XCBConnection&) = delete;

public:
XCBAtoms(xcb_connection_t* xcb_connection);
xcb_connection_t* const xcb_connection;

public:
class Atom
{
public:
/// Context should outlive the atom
Atom(std::string const& name, Context const& context);
Atom(std::string const& name, XCBConnection* connection);
operator xcb_atom_t() const;
auto name() const -> std::string;

Expand All @@ -51,7 +56,7 @@ class XCBAtoms
Atom(Atom&&) = delete;
Atom& operator=(Atom&) = delete;

Context const& context;
XCBConnection* const connection;
std::string const name_;
xcb_intern_atom_cookie_t const cookie;
std::experimental::optional<xcb_atom_t> mutable atom;
Expand Down Expand Up @@ -122,13 +127,8 @@ class XCBAtoms
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
#endif // MIR_FRONTEND_XCB_CONNECTION_H
Loading