Skip to content

Commit

Permalink
[skip ci] RAII wmDeleteMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
archibate committed Jun 6, 2020
1 parent 916c520 commit 476eea5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion taichi/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ class GUIBaseX11 {
void *visual;
unsigned long window;
CXImage *img;
void *wmDeleteMessage;
std::vector<char> wmDeleteMessage;
};

using GUIBase = GUIBaseX11;
Expand Down
9 changes: 4 additions & 5 deletions taichi/gui/x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void GUI::process_event() {
break;
case ClientMessage:
// https://stackoverflow.com/questions/10792361/how-do-i-gracefully-exit-an-x11-event-loop
if (ev.xclient.data.l[0] == *(Atom *)wmDeleteMessage) {
if (ev.xclient.data.l[0] == *(Atom *)wmDeleteMessage.data()) {
key_events.push_back(
KeyEvent{KeyEvent::Type::press, "WMClose", cursor_pos});
should_close++;
Expand Down Expand Up @@ -123,10 +123,10 @@ void GUI::create_window() {
ButtonPressMask | ExposureMask | KeyPressMask | KeyReleaseMask |
ButtonPress | ButtonReleaseMask | EnterWindowMask |
LeaveWindowMask | PointerMotionMask);
wmDeleteMessage = std::malloc(sizeof(Atom));
*(Atom *)wmDeleteMessage =
wmDeleteMessage = std::vector<char>(sizeof(Atom));
*(Atom *)wmDeleteMessage.data() =
XInternAtom((Display *)display, "WM_DELETE_WINDOW", False);
XSetWMProtocols((Display *)display, window, (Atom *)wmDeleteMessage, 1);
XSetWMProtocols((Display *)display, window, (Atom *)wmDeleteMessage.data(), 1);
XMapWindow((Display *)display, window);
img = new CXImage((Display *)display, (Visual *)visual, width, height);
}
Expand All @@ -143,7 +143,6 @@ void GUI::set_title(std::string title) {

GUI::~GUI() {
XCloseDisplay((Display *)display);
std::free(wmDeleteMessage);
delete img;
}

Expand Down

0 comments on commit 476eea5

Please sign in to comment.