21#include <X11/XKBlib.h>
28 Display* display = (Display*)platformData;
31 Window_unix*
window =
new Window_unix();
32 if (!
window->initWindow(display)) {
40const long kEventMask = ExposureMask | StructureNotifyMask |
41 KeyPressMask | KeyReleaseMask |
42 PointerMotionMask | ButtonPressMask | ButtonReleaseMask;
54 constexpr int initialWidth = 1280;
55 constexpr int initialHeight = 960;
62 static int constexpr kChooseFBConfigAtt[] = {
63 GLX_RENDER_TYPE, GLX_RGBA_BIT,
64 GLX_DOUBLEBUFFER, True,
69 int chooseVisualAtt[] = {
77 static const GLint kChooseFBConifgAttCnt =
std::size(kChooseFBConfigAtt);
78 GLint msaaChooseFBConfigAtt[kChooseFBConifgAttCnt + 4];
79 memcpy(msaaChooseFBConfigAtt, kChooseFBConfigAtt,
sizeof(kChooseFBConfigAtt));
80 SkASSERT(None == msaaChooseFBConfigAtt[kChooseFBConifgAttCnt - 1]);
81 msaaChooseFBConfigAtt[kChooseFBConifgAttCnt - 1] = GLX_SAMPLE_BUFFERS_ARB;
82 msaaChooseFBConfigAtt[kChooseFBConifgAttCnt + 0] = 1;
83 msaaChooseFBConfigAtt[kChooseFBConifgAttCnt + 1] = GLX_SAMPLES_ARB;
85 msaaChooseFBConfigAtt[kChooseFBConifgAttCnt + 3] = None;
87 fFBConfig = glXChooseFBConfig(fDisplay, DefaultScreen(fDisplay), msaaChooseFBConfigAtt, &n);
89 fVisualInfo = glXGetVisualFromFBConfig(fDisplay, *fFBConfig);
91 static const GLint kChooseVisualAttCnt =
std::size(chooseVisualAtt);
92 GLint msaaChooseVisualAtt[kChooseVisualAttCnt + 4];
93 memcpy(msaaChooseVisualAtt, chooseVisualAtt,
sizeof(chooseVisualAtt));
94 SkASSERT(None == msaaChooseVisualAtt[kChooseVisualAttCnt - 1]);
95 msaaChooseFBConfigAtt[kChooseVisualAttCnt - 1] = GLX_SAMPLE_BUFFERS_ARB;
96 msaaChooseFBConfigAtt[kChooseVisualAttCnt + 0] = 1;
97 msaaChooseFBConfigAtt[kChooseVisualAttCnt + 1] = GLX_SAMPLES_ARB;
98 msaaChooseFBConfigAtt[kChooseVisualAttCnt + 2] =
100 msaaChooseFBConfigAtt[kChooseVisualAttCnt + 3] = None;
101 fVisualInfo = glXChooseVisual(display, DefaultScreen(display), msaaChooseVisualAtt);
105 if (
nullptr == fVisualInfo) {
107 fFBConfig = glXChooseFBConfig(fDisplay, DefaultScreen(fDisplay), kChooseFBConfigAtt, &n);
109 fVisualInfo = glXGetVisualFromFBConfig(fDisplay, *fFBConfig);
111 fVisualInfo = glXChooseVisual(display, DefaultScreen(display), chooseVisualAtt);
117 Colormap colorMap = XCreateColormap(display,
118 RootWindow(display, fVisualInfo->screen),
121 XSetWindowAttributes swa;
122 swa.colormap = colorMap;
124 fWindow = XCreateWindow(display,
125 RootWindow(display, fVisualInfo->screen),
127 initialWidth, initialHeight,
132 CWEventMask | CWColormap,
138 fWindow = XCreateSimpleWindow(display,
139 DefaultRootWindow(display),
141 initialWidth, initialHeight,
155 fWmDeleteMessage = XInternAtom(display,
"WM_DELETE_WINDOW",
False);
156 XSetWMProtocols(display, fWindow, &fWmDeleteMessage, 1);
162 fPendingPaint =
false;
163 fPendingResize =
false;
168void Window_unix::closeWindow() {
172 XFreeGC(fDisplay, fGC);
176 XDestroyWindow(fDisplay, fWindow);
184 fVisualInfo =
nullptr;
191 static const struct {
223 if (gPair[
i].fXK == keysym) {
224 return gPair[
i].fKey;
231 static const struct {
243 modifiers |= gModifiers[
i].fSkMask;
250 switch (
event.type) {
253 fGC = XCreateGC(fDisplay, fWindow, 0,
nullptr);
258 if ((Atom)
event.xclient.data.l[0] == fWmDeleteMessage &&
265 switch (
event.xbutton.button) {
280 if (
event.xbutton.button == Button1) {
292 int shiftLevel = (
event.xkey.state & ShiftMask) ? 1 : 0;
293 KeySym keysym = XkbKeycodeToKeysym(fDisplay,
event.xkey.
keycode, 0, shiftLevel);
297 if (keysym == XK_Escape) {
310 int shiftLevel = (
event.xkey.state & ShiftMask) ? 1 : 0;
311 KeySym keysym = XkbKeycodeToKeysym(fDisplay,
event.xkey.
keycode,
318 case SelectionClear: {
320 fClipboardText.clear();
323 case SelectionRequest: {
324 Atom UTF8 = XInternAtom(fDisplay,
"UTF8_STRING", 0),
325 CLIPBOARD = XInternAtom(fDisplay,
"CLIPBOARD", 0);
327 const XSelectionRequestEvent* xsr = &
event.xselectionrequest;
329 XSelectionEvent xsel = {};
330 xsel.type = SelectionNotify;
331 xsel.requestor = xsr->requestor;
332 xsel.selection = xsr->selection;
333 xsel.target = xsr->target;
334 xsel.property = xsr->property;
335 xsel.time = xsr->time;
337 if (xsr->selection != CLIPBOARD) {
342 if (fClipboardText.empty() || xsr->target != UTF8 || xsr->property == None) {
344 xsel.property = None;
345 XSendEvent(fDisplay, xsr->requestor, True, NoEventMask, (XEvent*)&xsel);
349 XChangeProperty(fDisplay, xsr->requestor, xsr->property, UTF8, 8,
350 PropModeReplace, (
unsigned char*)fClipboardText.data(),
351 fClipboardText.length());
352 XSendEvent(fDisplay, xsr->requestor, True, NoEventMask, (XEvent*)&xsel);
366 XTextProperty textproperty;
367 if (!XStringListToTextProperty(
const_cast<char**
>(&title), 1, &textproperty)) {
370 XSetWMName(fDisplay, fWindow, &textproperty);
371 XFree(textproperty.value);
375 XMapWindow(fDisplay, fWindow);
379 fBackend = attachType;
389 XWindowAttributes attrs;
390 if (XGetWindowAttributes(fDisplay, fWindow, &attrs)) {
391 winInfo.
fWidth = attrs.width;
392 winInfo.
fHeight = attrs.height;
397 switch (attachType) {
398#if defined(SK_DAWN) && defined(SK_GRAPHITE)
399 case kGraphiteDawn_BackendType:
405 case kVulkan_BackendType:
409#if defined(SK_VULKAN) && defined(SK_GRAPHITE)
410 case kGraphiteVulkan_BackendType:
415 case kNativeGL_BackendType:
431 event.xexpose.send_event = True;
432 event.xexpose.display = fDisplay;
433 event.xexpose.window = fWindow;
436 event.xexpose.width = this->
width();
437 event.xexpose.height = this->
height();
438 event.xexpose.count = 0;
440 XSendEvent(fDisplay, fWindow,
False, 0, &
event);
444#if defined(SK_VULKAN)
447 if (fBackend == kVulkan_BackendType && allowReattach) {
461 Atom UTF8 = XInternAtom(fDisplay,
"UTF8_STRING", 0),
462 CLIPBOARD = XInternAtom(fDisplay,
"CLIPBOARD", 0),
463 XSEL_DATA = XInternAtom(fDisplay,
"XSEL_DATA", 0);
467 XConvertSelection(fDisplay, CLIPBOARD, UTF8, XSEL_DATA, fWindow, CurrentTime);
469 XNextEvent(fDisplay, &
event);
470 if (
event.type == SelectionNotify &&
471 event.xselection.selection == CLIPBOARD &&
472 event.xselection.property != None) {
477 unsigned long nitems, bytes_after;
481 XSelectionEvent xsel =
event.xselection;
482 XGetWindowProperty(xsel.display, xsel.requestor, xsel.property, 0,
484 &nitems, &bytes_after, (
unsigned char**)&
data);
487 fClipboardText.assign(
data, nitems);
490 XDeleteProperty(xsel.display, xsel.requestor, xsel.property);
492 return fClipboardText.c_str();
496 fClipboardText.assign(
text);
499 Atom CLIPBOARD = XInternAtom(fDisplay,
"CLIPBOARD", 0);
500 XSetSelectionOwner(fDisplay, CLIPBOARD, fWindow, CurrentTime);
static constexpr bool SkToBool(const T &x)
bool handleEvent(const XEvent &event)
void setTitle(const char *) override
const char * getClipboardText() override
bool attach(BackendType) override
static SkTDynamicHash< Window_unix, XWindow > gWindowMap
bool initWindow(Display *display)
void setClipboardText(const char *) override
void setRequestedDisplayParams(const DisplayParams &, bool allowReattach) override
bool onKey(skui::Key key, skui::InputState state, skui::ModifierKey modifiers)
bool onChar(SkUnichar c, skui::ModifierKey modifiers)
static Window * CreateNativeWindow(void *platformData)
virtual void setRequestedDisplayParams(const DisplayParams &, bool allowReattach=true)
bool onMouseWheel(float delta, int x, int y, skui::ModifierKey modifiers)
DisplayParams fRequestedDisplayParams
std::unique_ptr< skwindow::WindowContext > fWindowContext
bool onMouse(int x, int y, skui::InputState state, skui::ModifierKey modifiers)
const EmbeddedViewParams * params
uint32_t uint32_t * format
long keysym2ucs(KeySym keysym)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
static skui::ModifierKey get_modifiers(const XEvent &event)
static skui::Key get_key(KeySym keysym)
@ kHome
the home key - added to match android
std::unique_ptr< WindowContext > MakeGLForXlib(const XlibWindowInfo &winInfo, const DisplayParams ¶ms)
std::unique_ptr< WindowContext > MakeGraphiteDawnVulkanForXlib(const XlibWindowInfo &info, const DisplayParams ¶ms)
std::unique_ptr< WindowContext > MakeGraphiteVulkanForXlib(const XlibWindowInfo &info, const DisplayParams &displayParams)
std::unique_ptr< WindowContext > MakeRasterForXlib(const XlibWindowInfo &info, const DisplayParams ¶ms)
std::unique_ptr< WindowContext > MakeVulkanForXlib(const XlibWindowInfo &info, const DisplayParams &displayParams)
XVisualInfo * fVisualInfo
std::shared_ptr< const fml::Mapping > data