Skip to content

Commit

Permalink
Update documentation build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
MostlyKIGuess committed Jan 20, 2025
1 parent bd9616e commit 78a253f
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 124 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
sudo apt install -y build-essential sudo git wget curl python3-sphinx rsync
# install sugar-toolkit-gtk3 dependencies
sudo apt install -y python-all-dev python3-all-dev libgtk-3-dev
sudo apt install -y python-dev-is-python3 python3-dev libgtk-3-dev
sudo apt install -y libgdk-pixbuf2.0-dev libsm-dev libice-dev librsvg2-dev
sudo apt install -y libxfixes-dev libxi-dev libx11-dev gettext intltool
sudo apt install -y libxml-parser-perl x11proto-core-dev libasound2-dev
Expand Down
5 changes: 3 additions & 2 deletions ci/docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ sudo make

# make documentation
show-green "Building documentation"
sphinx-build -b html doc doc/_build/html
./make-doc.sh
mkdir deploy
mkdir -p deploy
cp -r doc/_build/html deploy/sugar3
touch deploy/.nojekyll
# create an index.html so that users don't become confused
Expand All @@ -29,4 +30,4 @@ echo "<h1>Page Moved</h1>" > deploy/index.html
echo "<p>We have moved this page to <a href=\"https://github.com/sugarlabs/sugar-docs/blob/master/README.md\">GitHub</a>.</p>" >> deploy/index.html
echo "<p>How did you get here? Please <a href=\"https://github.com/sugarlabs/sugar-docs/issues\">report</a> any lingering links.</p>" >> deploy/index.html

show-green "Done"
show-green "Done"
8 changes: 4 additions & 4 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ endif
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS)
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .

Expand Down Expand Up @@ -52,9 +52,9 @@ clean:
rm -rf $(BUILDDIR)/*

html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."

dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
Expand Down
13 changes: 7 additions & 6 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx'
'sphinx.ext.intersphinx',
'sphinx.ext.napoleon'
]
if major >= 1 and minor >= 3:
# Included in Sphinx 1.3
extensions.append('sphinx.ext.napoleon')
else:
extensions.append('sphinxcontrib.napoleon')
# if major >= 1 and minor >= 3:
# # Included in Sphinx 1.3
# extensions.append('sphinx.ext.napoleon')
# else:
# extensions.append('sphinxcontrib.napoleon')

intersphinx_mapping = {
'glib': ('http://lazka.github.io/pgi-docs/GLib-2.0', None),
Expand Down
13 changes: 12 additions & 1 deletion make-doc.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
#!/bin/sh
set -e

if [ ! -d "src" ]; then
echo "Error: ../src directory does not exist."
exit 1
fi

if [ ! -d "doc" ]; then
echo "Error: doc directory does not exist."
exit 1
fi

sphinx-apidoc --force --separate --output-dir=doc src
make -C doc html
make -C doc html
218 changes: 108 additions & 110 deletions src/sugar3/sugar-key-grabber.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <X11/extensions/XInput2.h>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>

#include "sugar-key-grabber.h"
#include "eggaccelerators.h"
#include "sugar-marshal.h"
Expand All @@ -37,9 +36,9 @@
#define USED_MODS (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)

enum {
KEY_PRESSED,
KEY_RELEASED,
N_SIGNALS
KEY_PRESSED,
KEY_RELEASED,
N_SIGNALS
};

typedef struct {
Expand All @@ -56,30 +55,30 @@ static guint signals[N_SIGNALS];
static void
free_key_info(Key *key_info)
{
g_free(key_info->key);
g_free(key_info);
g_free(key_info->key);
g_free(key_info);
}

static void
sugar_key_grabber_dispose (GObject *object)
{
SugarKeyGrabber *grabber = SUGAR_KEY_GRABBER(object);
SugarKeyGrabber *grabber = SUGAR_KEY_GRABBER(object);

if (grabber->keys) {
g_list_foreach(grabber->keys, (GFunc)free_key_info, NULL);
g_list_free(grabber->keys);
grabber->keys = NULL;
}
if (grabber->keys) {
g_list_foreach(grabber->keys, (GFunc)free_key_info, NULL);
g_list_free(grabber->keys);
grabber->keys = NULL;
}
}

static void
sugar_key_grabber_class_init(SugarKeyGrabberClass *grabber_class)
{
GObjectClass *g_object_class = G_OBJECT_CLASS (grabber_class);
GObjectClass *g_object_class = G_OBJECT_CLASS (grabber_class);

g_object_class->dispose = sugar_key_grabber_dispose;
g_object_class->dispose = sugar_key_grabber_dispose;

signals[KEY_PRESSED] = g_signal_new ("key-pressed",
signals[KEY_PRESSED] = g_signal_new ("key-pressed",
G_TYPE_FROM_CLASS (grabber_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (SugarKeyGrabberClass, key_pressed),
Expand All @@ -89,7 +88,7 @@ sugar_key_grabber_class_init(SugarKeyGrabberClass *grabber_class)
G_TYPE_UINT,
G_TYPE_UINT,
G_TYPE_UINT);
signals[KEY_RELEASED] = g_signal_new ("key-released",
signals[KEY_RELEASED] = g_signal_new ("key-released",
G_TYPE_FROM_CLASS (grabber_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (SugarKeyGrabberClass, key_released),
Expand All @@ -104,73 +103,73 @@ sugar_key_grabber_class_init(SugarKeyGrabberClass *grabber_class)
char *
sugar_key_grabber_get_key(SugarKeyGrabber *grabber, guint keycode, guint state)
{
GList *l;
GList *l;

for (l = grabber->keys; l != NULL; l = l->next) {
Key *keyinfo = (Key *)l->data;
if ((keyinfo->keycode == keycode) &&
((state & USED_MODS) == keyinfo->state)) {
return g_strdup(keyinfo->key);
}
}
for (l = grabber->keys; l != NULL; l = l->next) {
Key *keyinfo = (Key *)l->data;
if ((keyinfo->keycode == keycode) &&
((state & USED_MODS) == keyinfo->state)) {
return g_strdup(keyinfo->key);
}
}

return NULL;
return NULL;
}

static GdkFilterReturn
filter_events(GdkXEvent *xevent, GdkEvent *event, gpointer data)
{
SugarKeyGrabber *grabber = (SugarKeyGrabber *)data;
XEvent *xev = (XEvent *)xevent;

if (xev->type == KeyRelease) {
int return_value;
g_signal_emit (grabber, signals[KEY_RELEASED], 0, xev->xkey.keycode,
xev->xkey.state, xev->xkey.time, &return_value);
if(return_value)
return GDK_FILTER_REMOVE;
}

if (xev->type == KeyPress) {
int return_value;
g_signal_emit (grabber, signals[KEY_PRESSED], 0, xev->xkey.keycode,
xev->xkey.state, xev->xkey.time, &return_value);
if(return_value)
return GDK_FILTER_REMOVE;
}

if (xev->type == GenericEvent) {
XIDeviceEvent *ev;
int return_value = FALSE;

ev = (XIDeviceEvent *) ((XGenericEventCookie *) xev)->data;

if (ev->evtype == XI_KeyPress) {
g_signal_emit (grabber, signals[KEY_PRESSED], 0,
ev->detail, ev->mods.effective, ev->time, &return_value);
} else if (ev->evtype == XI_KeyRelease) {
g_signal_emit (grabber, signals[KEY_RELEASED], 0,
ev->detail, ev->mods.effective, ev->time, &return_value);
}

if (return_value)
return GDK_FILTER_REMOVE;
}


return GDK_FILTER_CONTINUE;
SugarKeyGrabber *grabber = (SugarKeyGrabber *)data;
XEvent *xev = (XEvent *)xevent;

if (xev->type == KeyRelease) {
int return_value;
g_signal_emit (grabber, signals[KEY_RELEASED], 0, xev->xkey.keycode,
xev->xkey.state, xev->xkey.time, &return_value);
if(return_value)
return GDK_FILTER_REMOVE;
}

if (xev->type == KeyPress) {
int return_value;
g_signal_emit (grabber, signals[KEY_PRESSED], 0, xev->xkey.keycode,
xev->xkey.state, xev->xkey.time, &return_value);
if(return_value)
return GDK_FILTER_REMOVE;
}

if (xev->type == GenericEvent) {
XIDeviceEvent *ev;
int return_value = FALSE;

ev = (XIDeviceEvent *) ((XGenericEventCookie *) xev)->data;

if (ev->evtype == XI_KeyPress) {
g_signal_emit (grabber, signals[KEY_PRESSED], 0,
ev->detail, ev->mods.effective, ev->time, &return_value);
} else if (ev->evtype == XI_KeyRelease) {
g_signal_emit (grabber, signals[KEY_RELEASED], 0,
ev->detail, ev->mods.effective, ev->time, &return_value);
}

if (return_value)
return GDK_FILTER_REMOVE;
}


return GDK_FILTER_CONTINUE;
}

static void
sugar_key_grabber_init(SugarKeyGrabber *grabber)
{
GdkScreen *screen;
GdkScreen *screen;

screen = gdk_screen_get_default();
grabber->root = gdk_screen_get_root_window(screen);
grabber->keys = NULL;
screen = gdk_screen_get_default();
grabber->root = gdk_screen_get_root_window(screen);
grabber->keys = NULL;

gdk_window_add_filter(grabber->root, filter_events, grabber);
gdk_window_add_filter(grabber->root, filter_events, grabber);
}

/* grab_key and grab_key_real are from
Expand Down Expand Up @@ -230,20 +229,19 @@ grab_key (SugarKeyGrabber *grabber, Key *key, gboolean grab)
**/
void
sugar_key_grabber_grab_keys(SugarKeyGrabber *grabber,
const gchar *keys[],
gint n_elements)
const gchar *keys[],
gint n_elements)
{
gint i;
const char *key;
Key *keyinfo = NULL;
gint min_keycodes, max_keycodes;

XDisplayKeycodes(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
&min_keycodes, &max_keycodes);

for (i = 0; i < n_elements; i++){
keyinfo = g_new0 (Key, 1);
keyinfo->key = g_strdup(keys[i]);
keyinfo = g_new0 (Key, 1);
keyinfo->key = g_strdup(keys[i]);

if (!egg_accelerator_parse_virtual (keys[i], &keyinfo->keysym,
&keyinfo->keycode,
Expand All @@ -257,12 +255,12 @@ sugar_key_grabber_grab_keys(SugarKeyGrabber *grabber,
continue;
}

gdk_error_trap_push();
gdk_x11_display_error_trap_push(gdk_display_get_default());

grab_key(grabber, keyinfo, TRUE);

gdk_flush();
gint error_code = gdk_error_trap_pop ();
gdk_display_flush(gdk_display_get_default());
gint error_code = gdk_x11_display_error_trap_pop(gdk_display_get_default());
if(!error_code)
grabber->keys = g_list_append(grabber->keys, keyinfo);
else if(error_code == BadAccess)
Expand All @@ -279,37 +277,37 @@ sugar_key_grabber_grab_keys(SugarKeyGrabber *grabber,
gboolean
sugar_key_grabber_is_modifier(SugarKeyGrabber *grabber, guint keycode, guint mask)
{
Display *xdisplay;
XModifierKeymap *modmap;
gint start, end, i, mod_index;
gboolean is_modifier = FALSE;

xdisplay = GDK_DISPLAY_XDISPLAY(gdk_display_get_default ());

modmap = XGetModifierMapping(xdisplay);

if (mask != -1) {
mod_index = 0;
mask = mask >> 1;
while (mask != 0) {
mask = mask >> 1;
mod_index += 1;
}
start = mod_index * modmap->max_keypermod;
end = (mod_index + 1) * modmap->max_keypermod;
} else {
start = 0;
end = 8 * modmap->max_keypermod;
}

for (i = start; i < end; i++) {
if (keycode == modmap->modifiermap[i]) {
is_modifier = TRUE;
break;
}
}

XFreeModifiermap (modmap);

return is_modifier;
Display *xdisplay;
XModifierKeymap *modmap;
gint start, end, i, mod_index;
gboolean is_modifier = FALSE;

xdisplay = GDK_DISPLAY_XDISPLAY(gdk_display_get_default ());

modmap = XGetModifierMapping(xdisplay);

if (mask != -1) {
mod_index = 0;
mask = mask >> 1;
while (mask != 0) {
mask = mask >> 1;
mod_index += 1;
}
start = mod_index * modmap->max_keypermod;
end = (mod_index + 1) * modmap->max_keypermod;
} else {
start = 0;
end = 8 * modmap->max_keypermod;
}

for (i = start; i < end; i++) {
if (keycode == modmap->modifiermap[i]) {
is_modifier = TRUE;
break;
}
}

XFreeModifiermap (modmap);

return is_modifier;
}

0 comments on commit 78a253f

Please sign in to comment.