Xlib + Cairo save content through resizing
I have a small GUI using Xlib and Cairo to draw simple stuff (Lines, Rectangles, Text) and I want to have the possibility to resize it (making it bigger than before) without losing the content like X11 usually handles resizes.
Cairo gives the function cairo_xlib_surface_set_size()
( https://www.cairographics.org/manual/cairo-XLib-Surfaces.html#cairo-xlib-surface-set-size )
but this also seems to delete all current content.
I've tried something along the lines of this how to save Drawing area's content after resizing window at cairo but without effect and I don't want to use Gtk because it's only a simple application.
1st approach (resize, no saving):
XSelectInput(display, window, ExposureMask | StructureNotifyMask);
switch (event.type) {
case ConfigureNotify:
onConfigure(event);
break;
}
with
onConfigure(XEvent e) {
XLockDisplay(display);
// if resize
if (e.xconfigure.width != width && e.xconfigure.height != height){
width = e.xconfigure.width;
height = e.xconfigure.height;
cairo_xlib_surface_set_size (sfc, width, height);
clear(); //without clear the screen just takes on a random color
}
cairo_surface_flush(sfc);
XUnlockDisplay(display);
}
I've also tried delving into the Cairo source code to look what cairo_xlib_surface_set_size is supposed to do and I didn't see anything to save content.
2nd approach (saving, no resize):
XSelectInput(display, window, ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask | ResizeRedirectMask);
switch (event.type) {
case ResizeRequest:
onResize(event);
break;
}
with
onConfigure(XEvent e) {
XLockDisplay(display);
cairo_surface_flush(sfc);
cairo_xlib_surface_set_size(sfc, e.xresizerequest.width, e.xresizerequest.height);
width = e.xresizerequest.width;
height = e.xresizerequest.height;
XFlush(display);
XUnlockDisplay(display);
}
This 2nd approach does resize the window and keeps the content, while also setting the size of the surface. But for some reason it still clips in the old size. The purple lines should go all the way to bottom/right side, but stay in the old surface size.
I don't really understand why the 2nd approach does what it does.
c++ x11 cairo
add a comment |
I have a small GUI using Xlib and Cairo to draw simple stuff (Lines, Rectangles, Text) and I want to have the possibility to resize it (making it bigger than before) without losing the content like X11 usually handles resizes.
Cairo gives the function cairo_xlib_surface_set_size()
( https://www.cairographics.org/manual/cairo-XLib-Surfaces.html#cairo-xlib-surface-set-size )
but this also seems to delete all current content.
I've tried something along the lines of this how to save Drawing area's content after resizing window at cairo but without effect and I don't want to use Gtk because it's only a simple application.
1st approach (resize, no saving):
XSelectInput(display, window, ExposureMask | StructureNotifyMask);
switch (event.type) {
case ConfigureNotify:
onConfigure(event);
break;
}
with
onConfigure(XEvent e) {
XLockDisplay(display);
// if resize
if (e.xconfigure.width != width && e.xconfigure.height != height){
width = e.xconfigure.width;
height = e.xconfigure.height;
cairo_xlib_surface_set_size (sfc, width, height);
clear(); //without clear the screen just takes on a random color
}
cairo_surface_flush(sfc);
XUnlockDisplay(display);
}
I've also tried delving into the Cairo source code to look what cairo_xlib_surface_set_size is supposed to do and I didn't see anything to save content.
2nd approach (saving, no resize):
XSelectInput(display, window, ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask | ResizeRedirectMask);
switch (event.type) {
case ResizeRequest:
onResize(event);
break;
}
with
onConfigure(XEvent e) {
XLockDisplay(display);
cairo_surface_flush(sfc);
cairo_xlib_surface_set_size(sfc, e.xresizerequest.width, e.xresizerequest.height);
width = e.xresizerequest.width;
height = e.xresizerequest.height;
XFlush(display);
XUnlockDisplay(display);
}
This 2nd approach does resize the window and keeps the content, while also setting the size of the surface. But for some reason it still clips in the old size. The purple lines should go all the way to bottom/right side, but stay in the old surface size.
I don't really understand why the 2nd approach does what it does.
c++ x11 cairo
Do you handle Expose events? Do you redraw the content of your window when the size changes? Could you provide some self-contained example program reproducing the problem so that I could play with that?
– Uli Schlachter
Nov 20 '18 at 10:10
add a comment |
I have a small GUI using Xlib and Cairo to draw simple stuff (Lines, Rectangles, Text) and I want to have the possibility to resize it (making it bigger than before) without losing the content like X11 usually handles resizes.
Cairo gives the function cairo_xlib_surface_set_size()
( https://www.cairographics.org/manual/cairo-XLib-Surfaces.html#cairo-xlib-surface-set-size )
but this also seems to delete all current content.
I've tried something along the lines of this how to save Drawing area's content after resizing window at cairo but without effect and I don't want to use Gtk because it's only a simple application.
1st approach (resize, no saving):
XSelectInput(display, window, ExposureMask | StructureNotifyMask);
switch (event.type) {
case ConfigureNotify:
onConfigure(event);
break;
}
with
onConfigure(XEvent e) {
XLockDisplay(display);
// if resize
if (e.xconfigure.width != width && e.xconfigure.height != height){
width = e.xconfigure.width;
height = e.xconfigure.height;
cairo_xlib_surface_set_size (sfc, width, height);
clear(); //without clear the screen just takes on a random color
}
cairo_surface_flush(sfc);
XUnlockDisplay(display);
}
I've also tried delving into the Cairo source code to look what cairo_xlib_surface_set_size is supposed to do and I didn't see anything to save content.
2nd approach (saving, no resize):
XSelectInput(display, window, ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask | ResizeRedirectMask);
switch (event.type) {
case ResizeRequest:
onResize(event);
break;
}
with
onConfigure(XEvent e) {
XLockDisplay(display);
cairo_surface_flush(sfc);
cairo_xlib_surface_set_size(sfc, e.xresizerequest.width, e.xresizerequest.height);
width = e.xresizerequest.width;
height = e.xresizerequest.height;
XFlush(display);
XUnlockDisplay(display);
}
This 2nd approach does resize the window and keeps the content, while also setting the size of the surface. But for some reason it still clips in the old size. The purple lines should go all the way to bottom/right side, but stay in the old surface size.
I don't really understand why the 2nd approach does what it does.
c++ x11 cairo
I have a small GUI using Xlib and Cairo to draw simple stuff (Lines, Rectangles, Text) and I want to have the possibility to resize it (making it bigger than before) without losing the content like X11 usually handles resizes.
Cairo gives the function cairo_xlib_surface_set_size()
( https://www.cairographics.org/manual/cairo-XLib-Surfaces.html#cairo-xlib-surface-set-size )
but this also seems to delete all current content.
I've tried something along the lines of this how to save Drawing area's content after resizing window at cairo but without effect and I don't want to use Gtk because it's only a simple application.
1st approach (resize, no saving):
XSelectInput(display, window, ExposureMask | StructureNotifyMask);
switch (event.type) {
case ConfigureNotify:
onConfigure(event);
break;
}
with
onConfigure(XEvent e) {
XLockDisplay(display);
// if resize
if (e.xconfigure.width != width && e.xconfigure.height != height){
width = e.xconfigure.width;
height = e.xconfigure.height;
cairo_xlib_surface_set_size (sfc, width, height);
clear(); //without clear the screen just takes on a random color
}
cairo_surface_flush(sfc);
XUnlockDisplay(display);
}
I've also tried delving into the Cairo source code to look what cairo_xlib_surface_set_size is supposed to do and I didn't see anything to save content.
2nd approach (saving, no resize):
XSelectInput(display, window, ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask | ResizeRedirectMask);
switch (event.type) {
case ResizeRequest:
onResize(event);
break;
}
with
onConfigure(XEvent e) {
XLockDisplay(display);
cairo_surface_flush(sfc);
cairo_xlib_surface_set_size(sfc, e.xresizerequest.width, e.xresizerequest.height);
width = e.xresizerequest.width;
height = e.xresizerequest.height;
XFlush(display);
XUnlockDisplay(display);
}
This 2nd approach does resize the window and keeps the content, while also setting the size of the surface. But for some reason it still clips in the old size. The purple lines should go all the way to bottom/right side, but stay in the old surface size.
I don't really understand why the 2nd approach does what it does.
c++ x11 cairo
c++ x11 cairo
asked Nov 17 '18 at 12:32
B. KalB. Kal
12
12
Do you handle Expose events? Do you redraw the content of your window when the size changes? Could you provide some self-contained example program reproducing the problem so that I could play with that?
– Uli Schlachter
Nov 20 '18 at 10:10
add a comment |
Do you handle Expose events? Do you redraw the content of your window when the size changes? Could you provide some self-contained example program reproducing the problem so that I could play with that?
– Uli Schlachter
Nov 20 '18 at 10:10
Do you handle Expose events? Do you redraw the content of your window when the size changes? Could you provide some self-contained example program reproducing the problem so that I could play with that?
– Uli Schlachter
Nov 20 '18 at 10:10
Do you handle Expose events? Do you redraw the content of your window when the size changes? Could you provide some self-contained example program reproducing the problem so that I could play with that?
– Uli Schlachter
Nov 20 '18 at 10:10
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53351303%2fxlib-cairo-save-content-through-resizing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53351303%2fxlib-cairo-save-content-through-resizing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Do you handle Expose events? Do you redraw the content of your window when the size changes? Could you provide some self-contained example program reproducing the problem so that I could play with that?
– Uli Schlachter
Nov 20 '18 at 10:10