Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8936681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:16:03+00:00 2026-06-15T10:16:03+00:00

Beginner user of C here. I’m trying to build a library in C using

  • 0

Beginner user of C here.

I’m trying to build a library in C using X11/Xlib so I can use it just for little projects and I’m running into a problem when trying to handle events to get input(button presses and key presses) from the user. It works fine for a while and then it starts to build up a significant lag over time.

Right now what I have is my program checking if there is an event waiting and if there is, retrieving it.

I think that my problem right now is that the events are getting stored in memory and its bogging down the program. But that’s just a total guess.

Any help will be appreciated. Thank you.

EDIT: Forgot code (I knew I forgot something)

The two functions in question are:

int event_waiting()
{
    XEvent event;

    if(XCheckMaskEvent(dspy,-1,&event)) {
        if(event.type==KeyPress) {
            XPutBackEvent(dspy,&event);
            return 1;
        } else if (event.type==ButtonPress) {
            XPutBackEvent(dspy,&event);
            return 1;
        }
    } /* <<=== added missing close-curly here */
    return 0;
}

char wait()
{
    XEvent event;
    XNextEvent(dspy,&event);
    if(event.type==KeyPress) {
        saved_x = event.xkey.x;
        saved_y = event.xkey.y;
        return XLookupKeysym(&event.xkey,0);
    } else if(event.type==ButtonPress) {
        saved_x = event.xkey.x;
        saved_y = event.xkey.y;
        return event.xbutton.button;
    }
}

And then they are called in the main like so,

if (event_waiting()){
  char c = wait();
  //Switch case goes here
}

EDIT 2: UPDATED CODE

XEvent event;
if(XCheckMaskEvent(display,-1,&event)) 
{
    if(event.type==KeyPress) {
        XPutBackEvent(display,&event);
        return 1;
    } else if (event.type==ButtonPress) {
        XPutBackEvent(display,&event);
        return 1;
    }
}
XFlush(display);
return 0;

`

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:16:04+00:00Added an answer on June 15, 2026 at 10:16 am

    The lag, which gets worse over time, means that you have many untouched events in your event queue, which slows down XCheckMaskEvent().

    Try specifying events using XSelectInput(... ButtonPressMask | KeyPressMask), and try flushing the event queue using XFlush() if there is no event in which you are interested:

        if(event.type==KeyPress) {
            XPutBackEvent(dspy,&event);
            return 1;
        } else if (event.type==ButtonPress) {
            XPutBackEvent(dspy,&event);
            return 1;
        } else {
            XFlush(dspy); // this
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Beginner here trying to get a pipeline working in bash. If somebody can see
PowerShell/xml beginner here.... I'm trying to append to or remove empty xml nodes using
RoR beginner here using rails 3.2.3 and ruby 1.9.3 Currently I am trying to
I am a beginner in PHP. How can I restrict user access to controller.php
Beginner at Django here, I've been trying to fix this for a long time
Python beginner here. I've looked around and found similar questions but can't quite cobble
i'm a beginner in PHP and i'm trying to make a login screen using
(R beginner here...) I have a dataset like: > head(q) Date Time System User
Django advanced beginner here. I'm banging my head against the wall trying to figure
Beginner question perhaps: I'm trying to check my user permissions from facebook with Koala.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.