<commit_before>#include "e.h"
#include "e_mod_main.h"

/* gadcon requirements */
static E_Gadcon_Client *_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style);
static void _gc_shutdown(E_Gadcon_Client *gcc);
static void _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient);
static char *_gc_label(E_Gadcon_Client_Class *client_class);
static Evas_Object *_gc_icon(E_Gadcon_Client_Class *client_class, Evas *evas);
static const char *_gc_id_new(E_Gadcon_Client_Class *client_class);

/* and actually define the gadcon class that this module provides (just 1) */
static const E_Gadcon_Client_Class _gadcon_class =
{
   GADCON_CLIENT_CLASS_VERSION,
     "backlight",
     {
        _gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon, _gc_id_new, NULL, NULL
     },
   E_GADCON_CLIENT_STYLE_PLAIN
};

/* actual module specifics */
typedef struct _Instance Instance;

struct _Instance
{
   E_Gadcon_Client *gcc;
   Evas_Object     *o_backlight, *o_table, *o_slider;
   E_Gadcon_Popup  *popup;
   E_Menu          *menu;
   double           val;
   Ecore_X_Window   input_win;
   Ecore_Event_Handler *hand_mouse_down;
   Ecore_Event_Handler *hand_key_down;
};

static Eina_List *backlight_instances = NULL;
static E_Module *backlight_module = NULL;
static E_Action *act = NULL;

static void _backlight_popup_free(Instance *inst);

static void
_backlight_input_win_del(Instance *inst)
{
   e_grabinput_release(0, inst->input_win);
   ecore_x_window_free(inst->input_win);
   inst->input_win = 0;
   ecore_event_handler_del(inst->hand_mouse_down);
   inst->hand_mouse_down = NULL;
   ecore_event_handler_del(inst->hand_key_down);
   inst->hand_key_down = NULL;
}

static Eina_Bool
_backlight_input_win_mouse_down_cb(void *data, int type __UNUSED__, void *event)
{
   Ecore_Event_Mouse_Button *ev = event;
   Instance *inst = data;
   
   if (ev->window != inst->input_win) return ECORE_CALLBACK_PASS_ON;
   _backlight_popup_free(inst);
   return ECORE_CALLBACK_PASS_ON;
}

static Eina_Bool
_backlight_input_win_key_down_cb(void *data, int type __UNUSED__, void *event)
{
   Ecore_Event_Key *ev = event;
   Instance *inst = data;
   const char *keysym;
   
   if (ev->window != inst->input_win) return ECORE_CALLBACK_PASS_ON;
   
   keysym = ev->key;
   if (!strcmp(keysym, "Escape"))
      _backlight_popup_free(inst);
   else if ((!strcmp(keysym, "Up")) ||
            (!strcmp(keysym, "Left")) ||
            (!strcmp(keysym, "KP_Up")) ||
            (!strcmp(keysym, "KP_Left")) ||
            (!strcmp(keysym, "w")) ||
            (!strcmp(keysym, "d")) ||
            (!strcmp(keysym, "bracketright")) ||
            (!strcmp(keysym, "Prior")))
     {
        double v = inst->val + 0.1;
        if (v > 1.0) v = 1.0;
        e_widget_slider_value_double_set(inst->o_slider, v);
        inst->val = v;
        e_backlight_mode_set(inst->gcc->gadcon->zone, E_BACKLIGHT_MODE_NORMAL);
        e_backlight_level_set(inst->gcc->gadcon->zone, v, 0.0);
     }
   else if ((!strcmp(keysym, "Down")) ||
            (!strcmp(keysym, "Right")) ||
            (!strcmp(keysym, "KP_Down")) ||
            (!strcmp(keysym, "KP_Right")) ||
            (!strcmp(keysym, "s")) ||
            (!strcmp(keysym, "a")) ||
            (!strcmp(keysym, "bracketleft")) ||
            (!strcmp(keysym, "Next")))
     {
        double v = inst->val - 0.1;
        if (v < 0.0) v = 0.0;
        e_widget_slider_value_double_set(inst->o_slider, v);
        inst->val = v;
        e_backlight_mode_set(inst->gcc->gadcon->zone, E_BACKLIGHT_MODE_NORMAL);
        e_backlight_level_set(inst->gcc->gadcon->zone, v, 0.0);
     }
   else if ((!strcmp(keysym, "0")) ||
            (!strcmp(keysym, "1")) ||
            (!strcmp(keysym, "2")) ||
            (!strcmp(keysym, "3")) ||
            (!strcmp(keysym, "4")) ||
            (!strcmp(keysym, "5")) ||
            (!strcmp(keysym, "6")) ||
            (!strcmp(keysym, "7")) ||
            (!strcmp(keysym, "8")) ||
            (!strcmp(keysym, "9")))
     {
        double v = (double)atoi(keysym) / 9.0;
        e_widget_slider_value_double_set(inst->o_slider, v);
        inst->val = v;
        e_backlight_mode_set(inst->gcc->gadcon->zone, E_BACKLIGHT_MODE_NORMAL);
        e_backlight_level_set(inst->gcc->gadcon->zone, v, 0.0);
     }
   return ECORE_CALLBACK_PASS_ON;
}

static void
_backlight_input_win_new(Instance *inst)
{
   Ecore_X_Window_Configure_Mask mask;
   Ecore_X_Window w, popup_w;
   E_Manager *man;
   
   man = inst->gcc->gadcon->zone->container->manager;<commit_msg>make keybinding that toggles backlight toggle it down when grabbed<commit_after>#include "e.h"
#include "e_mod_main.h"

/* gadcon requirements */
static E_Gadcon_Client *_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style);
static void _gc_shutdown(E_Gadcon_Client *gcc);
static void _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient);
static char *_gc_label(E_Gadcon_Client_Class *client_class);
static Evas_Object *_gc_icon(E_Gadcon_Client_Class *client_class, Evas *evas);
static const char *_gc_id_new(E_Gadcon_Client_Class *client_class);

/* and actually define the gadcon class that this module provides (just 1) */
static const E_Gadcon_Client_Class _gadcon_class =
{
   GADCON_CLIENT_CLASS_VERSION,
     "backlight",
     {
        _gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon, _gc_id_new, NULL, NULL
     },
   E_GADCON_CLIENT_STYLE_PLAIN
};

/* actual module specifics */
typedef struct _Instance Instance;

struct _Instance
{
   E_Gadcon_Client *gcc;
   Evas_Object     *o_backlight, *o_table, *o_slider;
   E_Gadcon_Popup  *popup;
   E_Menu          *menu;
   double           val;
   Ecore_X_Window   input_win;
   Ecore_Event_Handler *hand_mouse_down;
   Ecore_Event_Handler *hand_key_down;
};

static Eina_List *backlight_instances = NULL;
static E_Module *backlight_module = NULL;
static E_Action *act = NULL;

static void _backlight_popup_free(Instance *inst);

static void
_backlight_input_win_del(Instance *inst)
{
   e_grabinput_release(0, inst->input_win);
   ecore_x_window_free(inst->input_win);
   inst->input_win = 0;
   ecore_event_handler_del(inst->hand_mouse_down);
   inst->hand_mouse_down = NULL;
   ecore_event_handler_del(inst->hand_key_down);
   inst->hand_key_down = NULL;
}

static Eina_Bool
_backlight_input_win_mouse_down_cb(void *data, int type __UNUSED__, void *event)
{
   Ecore_Event_Mouse_Button *ev = event;
   Instance *inst = data;
   
   if (ev->window != inst->input_win) return ECORE_CALLBACK_PASS_ON;
   _backlight_popup_free(inst);
   return ECORE_CALLBACK_PASS_ON;
}

static Eina_Bool
_backlight_input_win_key_down_cb(void *data, int type __UNUSED__, void *event)
{
   Ecore_Event_Key *ev = event;
   Instance *inst = data;
   const char *keysym;
   
   if (ev->window != inst->input_win) return ECORE_CALLBACK_PASS_ON;
   
   keysym = ev->key;
   if (!strcmp(keysym, "Escape"))
      _backlight_popup_free(inst);
   else if ((!strcmp(keysym, "Up")) ||
            (!strcmp(keysym, "Left")) ||
            (!strcmp(keysym, "KP_Up")) ||
            (!strcmp(keysym, "KP_Left")) ||
            (!strcmp(keysym, "w")) ||
            (!strcmp(keysym, "d")) ||
            (!strcmp(keysym, "bracketright")) ||
            (!strcmp(keysym, "Prior")))
     {
        double v = inst->val + 0.1;
        if (v > 1.0) v = 1.0;
        e_widget_slider_value_double_set(inst->o_slider, v);
        inst->val = v;
        e_backlight_mode_set(inst->gcc->gadcon->zone, E_BACKLIGHT_MODE_NORMAL);
        e_backlight_level_set(inst->gcc->gadcon->zone, v, 0.0);
     }
   else if ((!strcmp(keysym, "Down")) ||
            (!strcmp(keysym, "Right")) ||
            (!strcmp(keysym, "KP_Down")) ||
            (!strcmp(keysym, "KP_Right")) ||
            (!strcmp(keysym, "s")) ||
            (!strcmp(keysym, "a")) ||
            (!strcmp(keysym, "bracketleft")) ||
            (!strcmp(keysym, "Next")))
     {
        double v = inst->val - 0.1;
        if (v < 0.0) v = 0.0;
        e_widget_slider_value_double_set(inst->o_slider, v);
        inst->val = v;
        e_backlight_mode_set(inst->gcc->gadcon->zone, E_BACKLIGHT_MODE_NORMAL);
        e_backlight_level_set(inst->gcc->gadcon->zone, v, 0.0);
     }
   else if ((!strcmp(keysym, "0")) ||
            (!strcmp(keysym, "1")) ||
            (!strcmp(keysym, "2")) ||
            (!strcmp(keysym, "3")) ||
            (!strcmp(keysym, "4")) ||
            (!strcmp(keysym, "5")) ||
            (!strcmp(keysym, "6")) ||
            (!strcmp(keysym, "7")) ||
            (!strcmp(keysym, "8")) ||
            (!strcmp(keysym, "9")))
     {
        double v = (double)atoi(keysym) / 9.0;
        e_widget_slider_value_double_set(inst->o_slider, v);
        inst->val = v;
        e_backlight_mode_set(inst->gcc->gadcon->zone, E_BACKLIGHT_MODE_NORMAL);
        e_backlight_level_set(inst->gcc->gadcon->zone, v, 0.0);
     }
   else
     {
        Eina_List *l;
        E_Config_Binding_Key *bind;
        E_Binding_Modifier mod;
        
        for (l = e_config->key_bindings; l; l = l->next)
          {
             bind = l->data;
             
             if (bind->action && strcmp(bind->action, "backlight")) continue;
             
             mod = 0;
             
             if (ev->modifiers & ECORE_EVENT_MODIFIER_SHIFT)
                mod |= E_BINDING_MODIFIER_SHIFT;
             if (ev->modifiers & ECORE_EVENT_MODIFIER_CTRL)
                mod |= E_BINDING_MODIFIER_CTRL;
             if (ev->modifiers & ECORE_EVENT_MODIFIER_ALT)
                mod |= E_BINDING_MODIFIER_ALT;
             if (ev->modifiers & ECORE_EVENT_MODIFIER_WIN)
                mod |= E_BINDING_MODIFIER_WIN;
             
             if (bind->key && (!strcmp(bind->key, ev->keyname)) &&
                 ((bind->modifiers == mod) || (bind->any_mod)))
               {
                  _backlight_popup_free(inst);
                  break;
               }
          }
     }
   return ECORE_CALLBACK_PASS_ON;
}

static void
_backlight_input_win_new(Instance *inst)
{
   Ecore_X_Window_Configure_Mask mask;
   Ecore_X_Window w, popup_w;
   E_Manager *man;
   
   man = inst->gcc->gadcon->zone->container->manager;
{'fraction_non_alphanumeric': 0.13598429062346587, 'fraction_numerical': 0.0065783014236622485, 'mean_word_length': 2.8833396873808614, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 105, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5431002', 'n_tokens_mistral': 3728, 'n_tokens_neox': 3715, 'n_words': 665}