Skip to content

Commit

Permalink
Merge pull request #177 from zandrmartin/add-pid-to-views
Browse files Browse the repository at this point in the history
implement wlc_view_get_pid()
  • Loading branch information
Cloudef committed Jul 30, 2016
2 parents 030c9c0 + 21e676d commit 4cbd5b7
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/wlc/wlc.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extern "C" {
#include <wlc/defines.h>
#include <wlc/geometry.h>
#include <xkbcommon/xkbcommon-keysyms.h>
#include <sys/types.h>

struct wlc_event_source;

Expand Down Expand Up @@ -61,6 +62,7 @@ enum wlc_view_property_update_bit {
WLC_BIT_PROPERTY_TITLE = 1<<0,
WLC_BIT_PROPERTY_CLASS = 1<<1,
WLC_BIT_PROPERTY_APP_ID = 1<<2,
WLC_BIT_PROPERTY_PID = 1<<3,
};

/** wlc_view_set_geometry(); Edges in interface interface.view.request.resize function. */
Expand Down Expand Up @@ -388,6 +390,9 @@ const char* wlc_view_get_class(wlc_handle view);
/** Get app id. (xdg-surface only) */
const char* wlc_view_get_app_id(wlc_handle view);

/** Get pid. */
pid_t wlc_view_get_pid(wlc_handle view);

/** -- Input API
* Very recent stuff, things may change.
* XXX: This api is dumb and assumes there is only single xkb state and keymap.
Expand Down
32 changes: 32 additions & 0 deletions man/man3/wlc_view_get_pid.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.TH WLC_VIEW_GET_PID 3 2016-07-29 WLC "WLC Core API Functions"

.SH NAME
wlc_view_get_pid - get the process id for a given view

.SH SYNOPSIS
.B #include <wlc/wlc.h>

.BI "pid_t wlc_view_get_pid(wlc_handle "view ");"

.SS Wayland protocol requirements:
.RS
.BR wlc_view_get_pid ():
xdg_shell
.RE

.SH DESCRIPTION
.BR wlc_view_get_pid ()
can be used to acquire the process id of a given
.I view.

.SH RETURN VALUE
.BR wlc_view_get_pid ()
returns the process id for
.I view
if it is available. Returns 0 (not a valid pid) if it is not. For X11
views this requires the application set the __NET_WM_PID property.

.SH ALSO SEE
The XDG Shell protocol extension
.UR http://cgit.freedesktop.org/wayland/weston/tree/protocol/xdg-shell.xml
.UE
26 changes: 26 additions & 0 deletions src/compositor/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,16 @@ wlc_view_set_app_id_ptr(struct wlc_view *view, const char *app_id)
}
}

void
wlc_view_set_pid_ptr(struct wlc_view *view, pid_t pid)
{
if (!view || view->data.pid == pid)
return;

view->data.pid = pid;
WLC_INTERFACE_EMIT(view.properties_updated, convert_to_wlc_handle(view), WLC_BIT_PROPERTY_PID);
}

void
wlc_view_close_ptr(struct wlc_view *view)
{
Expand Down Expand Up @@ -649,6 +659,22 @@ wlc_view_get_app_id(wlc_handle view)
return get_cstr(convert_from_wlc_handle(view, "view"), offsetof(struct wlc_view, data.app_id));
}

WLC_API pid_t
wlc_view_get_pid(wlc_handle handle)
{
struct wlc_view *view;
if(!(view = convert_from_wlc_handle(handle, "view")))
return 0;

if (is_x11_view(view)) {
return view->data.pid;
} else {
pid_t pid;
wl_client_get_credentials(wlc_view_get_client_ptr(view), &pid, NULL, NULL);
return pid;
}
}

void
wlc_view_release(struct wlc_view *view)
{
Expand Down
3 changes: 3 additions & 0 deletions src/compositor/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _WLC_VIEW_H_

#include <stdbool.h>
#include <sys/types.h>
#include <wlc/geometry.h>
#include <wayland-util.h>
#include <chck/pool/pool.h>
Expand Down Expand Up @@ -47,6 +48,7 @@ struct wlc_view {
struct chck_string app_id;
struct chck_string title;
struct chck_string _class;
pid_t pid;
enum wl_shell_surface_fullscreen_method fullscreen_mode;
bool minimized;
} data;
Expand Down Expand Up @@ -99,5 +101,6 @@ void wlc_view_set_minimized_ptr(struct wlc_view *view, bool minimized);
void wlc_view_set_title_ptr(struct wlc_view *view, const char *title, size_t length);
void wlc_view_set_class_ptr(struct wlc_view *view, const char *class_, size_t length);
void wlc_view_set_app_id_ptr(struct wlc_view *view, const char *app_id);
void wlc_view_set_pid_ptr(struct wlc_view *view, pid_t pid);

#endif /* _WLC_VIEW_H_ */
1 change: 1 addition & 0 deletions src/xwayland/xwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ read_properties(struct wlc_xwm *xwm, struct wlc_x11_window *win, const xcb_atom_
wlc_dlog(WLC_DBG_XWM, "WM_TRANSIENT_FOR: %u", *xid);
} else if (props[i] == x11.atoms[NET_WM_PID] && reply->type == XCB_ATOM_CARDINAL) {
// PID
wlc_view_set_pid_ptr(view, *(pid_t *)xcb_get_property_value(reply));
wlc_dlog(WLC_DBG_XWM, "NET_WM_PID");
} else if (props[i] == x11.atoms[NET_WM_WINDOW_TYPE] && reply->type == XCB_ATOM_ATOM) {
// Window type
Expand Down

0 comments on commit 4cbd5b7

Please sign in to comment.