ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I can create a window of the desired aspect ratio, but if the user want to resize the window, the aspect ratio will be lost.
Does anybody know if I can fix the aspect ratio or make the dimension of the window unchangeable?
You're talking about the user resizing the window, so obviously this window is a child of the root window. And it's the window manager which handles the resizing. So it's the window manager which will need to impose any constraints on user-requested window resizing (with the mouse).
So you're at the mercy of whatever window manager you're running, but that should be no problem.
You can request the minimum size, maximum size, minimum and maximum aspect ratio, increment for the window size (ever notice how xterm always keeps its height as a multiple of one line of print, and its width as a multiple of one character?), and something called win_gravity, which you probably won't need.
For more details, do this:
Code:
man xsizehints
Your code should look something like this:
Code:
XSizeHints *size_hints;
...
size_hints=XAllocSizeHints();
if(size_hints==NULL)
{
... handle the error
}
... futz around here, as suggested by "man xsizehints"
XSetWMNormalHints(the_display,
the_window,
size_hints,
);
Sorry, I'm still having problems here. I've tried something like this to fix the aspect ratio to 19:8 (the same as the video original source to be played back in the window):
If you check the values for min_aspect and max_aspect with this:
Code:
XSizeHints *hints_return = XAllocSizeHints();
long *supplied_return = (long *) malloc(sizeof(long));
XGetWMNormalHints(d, w, hints_return, supplied_return);
printf("minAs x %d y %d maxAs x %d y %d\n", hints_return->min_aspect.x, hints_return->min_aspect.y, hints_return->max_aspect.x, hints_return->max_aspect.y);
you get the correct values for the aspect ratio:
minAs x 19 y 8 maxAs x 19 y 8
However, the user can still change the aspect ratio to whatever it wants; the maximum and minimum sizes provided by min and max width and height are instead enforced.
I'm really confused at this point. What's happening?
Well, that's pretty interesting. I must confess I'd never looked into controlling the aspect ratio of a window until you raised the question. But just for kicks and grins, I ran the following shell script, and up popped a window with an enforced aspect ratio. When you run this shell script, what do you get?
Ok,
I've tried to run your code on two different OS:
- On ubuntu 9.04 it works fine
- On Max OS X persist the same problem of my code
So I think this is due to the different window manager that are running, true?
So I think this is due to the different window manager that are running, true?
Exactly.
Try running the following on your Mac. It's crude, but it might work. I'm dying of curiosity. Does it fix the problem?
Incidentally, if you're curious about why I turned EXACT on, try turning it off and turn VERBOSE on. You'll not only get interesting printed output as the size settles down, it will also make your window look a little funny as you resize it.
You can also try that experiment under Linux for amusement purposes if none of this changes anything on your Mac.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.