xserver

xserver with xephyr scale patch
git clone https://git.neptards.moe/u3shit/xserver.git
Log | Files | Refs | README | LICENSE

getfctl.c (10953B)


      1 /************************************************************
      2 
      3 Copyright 1989, 1998  The Open Group
      4 
      5 Permission to use, copy, modify, distribute, and sell this software and its
      6 documentation for any purpose is hereby granted without fee, provided that
      7 the above copyright notice appear in all copies and that both that
      8 copyright notice and this permission notice appear in supporting
      9 documentation.
     10 
     11 The above copyright notice and this permission notice shall be included in
     12 all copies or substantial portions of the Software.
     13 
     14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
     17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
     18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
     19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     20 
     21 Except as contained in this notice, the name of The Open Group shall not be
     22 used in advertising or otherwise to promote the sale, use or other dealings
     23 in this Software without prior written authorization from The Open Group.
     24 
     25 Copyright 1989 by Hewlett-Packard Company, Palo Alto, California.
     26 
     27 			All Rights Reserved
     28 
     29 Permission to use, copy, modify, and distribute this software and its
     30 documentation for any purpose and without fee is hereby granted,
     31 provided that the above copyright notice appear in all copies and that
     32 both that copyright notice and this permission notice appear in
     33 supporting documentation, and that the name of Hewlett-Packard not be
     34 used in advertising or publicity pertaining to distribution of the
     35 software without specific, written prior permission.
     36 
     37 HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
     38 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
     39 HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
     40 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
     41 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
     42 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
     43 SOFTWARE.
     44 
     45 ********************************************************/
     46 
     47 /********************************************************************
     48  *
     49  *  Get feedback control attributes for an extension device.
     50  *
     51  */
     52 
     53 #ifdef HAVE_DIX_CONFIG_H
     54 #include <dix-config.h>
     55 #endif
     56 
     57 #include "inputstr.h"           /* DeviceIntPtr      */
     58 #include <X11/extensions/XI.h>
     59 #include <X11/extensions/XIproto.h>
     60 #include "exglobals.h"
     61 
     62 #include "getfctl.h"
     63 
     64 /***********************************************************************
     65  *
     66  * This procedure gets the control attributes for an extension device,
     67  * for clients on machines with a different byte ordering than the server.
     68  *
     69  */
     70 
     71 int _X_COLD
     72 SProcXGetFeedbackControl(ClientPtr client)
     73 {
     74     REQUEST(xGetFeedbackControlReq);
     75     swaps(&stuff->length);
     76     return (ProcXGetFeedbackControl(client));
     77 }
     78 
     79 /***********************************************************************
     80  *
     81  * This procedure copies KbdFeedbackClass data, swapping if necessary.
     82  *
     83  */
     84 
     85 static void
     86 CopySwapKbdFeedback(ClientPtr client, KbdFeedbackPtr k, char **buf)
     87 {
     88     int i;
     89     xKbdFeedbackState *k2;
     90 
     91     k2 = (xKbdFeedbackState *) * buf;
     92     k2->class = KbdFeedbackClass;
     93     k2->length = sizeof(xKbdFeedbackState);
     94     k2->id = k->ctrl.id;
     95     k2->click = k->ctrl.click;
     96     k2->percent = k->ctrl.bell;
     97     k2->pitch = k->ctrl.bell_pitch;
     98     k2->duration = k->ctrl.bell_duration;
     99     k2->led_mask = k->ctrl.leds;
    100     k2->global_auto_repeat = k->ctrl.autoRepeat;
    101     for (i = 0; i < 32; i++)
    102         k2->auto_repeats[i] = k->ctrl.autoRepeats[i];
    103     if (client->swapped) {
    104         swaps(&k2->length);
    105         swaps(&k2->pitch);
    106         swaps(&k2->duration);
    107         swapl(&k2->led_mask);
    108         swapl(&k2->led_values);
    109     }
    110     *buf += sizeof(xKbdFeedbackState);
    111 }
    112 
    113 /***********************************************************************
    114  *
    115  * This procedure copies PtrFeedbackClass data, swapping if necessary.
    116  *
    117  */
    118 
    119 static void
    120 CopySwapPtrFeedback(ClientPtr client, PtrFeedbackPtr p, char **buf)
    121 {
    122     xPtrFeedbackState *p2;
    123 
    124     p2 = (xPtrFeedbackState *) * buf;
    125     p2->class = PtrFeedbackClass;
    126     p2->length = sizeof(xPtrFeedbackState);
    127     p2->id = p->ctrl.id;
    128     p2->accelNum = p->ctrl.num;
    129     p2->accelDenom = p->ctrl.den;
    130     p2->threshold = p->ctrl.threshold;
    131     if (client->swapped) {
    132         swaps(&p2->length);
    133         swaps(&p2->accelNum);
    134         swaps(&p2->accelDenom);
    135         swaps(&p2->threshold);
    136     }
    137     *buf += sizeof(xPtrFeedbackState);
    138 }
    139 
    140 /***********************************************************************
    141  *
    142  * This procedure copies IntegerFeedbackClass data, swapping if necessary.
    143  *
    144  */
    145 
    146 static void
    147 CopySwapIntegerFeedback(ClientPtr client, IntegerFeedbackPtr i, char **buf)
    148 {
    149     xIntegerFeedbackState *i2;
    150 
    151     i2 = (xIntegerFeedbackState *) * buf;
    152     i2->class = IntegerFeedbackClass;
    153     i2->length = sizeof(xIntegerFeedbackState);
    154     i2->id = i->ctrl.id;
    155     i2->resolution = i->ctrl.resolution;
    156     i2->min_value = i->ctrl.min_value;
    157     i2->max_value = i->ctrl.max_value;
    158     if (client->swapped) {
    159         swaps(&i2->length);
    160         swapl(&i2->resolution);
    161         swapl(&i2->min_value);
    162         swapl(&i2->max_value);
    163     }
    164     *buf += sizeof(xIntegerFeedbackState);
    165 }
    166 
    167 /***********************************************************************
    168  *
    169  * This procedure copies StringFeedbackClass data, swapping if necessary.
    170  *
    171  */
    172 
    173 static void
    174 CopySwapStringFeedback(ClientPtr client, StringFeedbackPtr s, char **buf)
    175 {
    176     int i;
    177     xStringFeedbackState *s2;
    178     KeySym *kptr;
    179 
    180     s2 = (xStringFeedbackState *) * buf;
    181     s2->class = StringFeedbackClass;
    182     s2->length = sizeof(xStringFeedbackState) +
    183         s->ctrl.num_symbols_supported * sizeof(KeySym);
    184     s2->id = s->ctrl.id;
    185     s2->max_symbols = s->ctrl.max_symbols;
    186     s2->num_syms_supported = s->ctrl.num_symbols_supported;
    187     *buf += sizeof(xStringFeedbackState);
    188     kptr = (KeySym *) (*buf);
    189     for (i = 0; i < s->ctrl.num_symbols_supported; i++)
    190         *kptr++ = *(s->ctrl.symbols_supported + i);
    191     if (client->swapped) {
    192         swaps(&s2->length);
    193         swaps(&s2->max_symbols);
    194         swaps(&s2->num_syms_supported);
    195         kptr = (KeySym *) (*buf);
    196         for (i = 0; i < s->ctrl.num_symbols_supported; i++, kptr++) {
    197             swapl(kptr);
    198         }
    199     }
    200     *buf += (s->ctrl.num_symbols_supported * sizeof(KeySym));
    201 }
    202 
    203 /***********************************************************************
    204  *
    205  * This procedure copies LedFeedbackClass data, swapping if necessary.
    206  *
    207  */
    208 
    209 static void
    210 CopySwapLedFeedback(ClientPtr client, LedFeedbackPtr l, char **buf)
    211 {
    212     xLedFeedbackState *l2;
    213 
    214     l2 = (xLedFeedbackState *) * buf;
    215     l2->class = LedFeedbackClass;
    216     l2->length = sizeof(xLedFeedbackState);
    217     l2->id = l->ctrl.id;
    218     l2->led_values = l->ctrl.led_values;
    219     l2->led_mask = l->ctrl.led_mask;
    220     if (client->swapped) {
    221         swaps(&l2->length);
    222         swapl(&l2->led_values);
    223         swapl(&l2->led_mask);
    224     }
    225     *buf += sizeof(xLedFeedbackState);
    226 }
    227 
    228 /***********************************************************************
    229  *
    230  * This procedure copies BellFeedbackClass data, swapping if necessary.
    231  *
    232  */
    233 
    234 static void
    235 CopySwapBellFeedback(ClientPtr client, BellFeedbackPtr b, char **buf)
    236 {
    237     xBellFeedbackState *b2;
    238 
    239     b2 = (xBellFeedbackState *) * buf;
    240     b2->class = BellFeedbackClass;
    241     b2->length = sizeof(xBellFeedbackState);
    242     b2->id = b->ctrl.id;
    243     b2->percent = b->ctrl.percent;
    244     b2->pitch = b->ctrl.pitch;
    245     b2->duration = b->ctrl.duration;
    246     if (client->swapped) {
    247         swaps(&b2->length);
    248         swaps(&b2->pitch);
    249         swaps(&b2->duration);
    250     }
    251     *buf += sizeof(xBellFeedbackState);
    252 }
    253 
    254 /***********************************************************************
    255  *
    256  * This procedure writes the reply for the xGetFeedbackControl function,
    257  * if the client and server have a different byte ordering.
    258  *
    259  */
    260 
    261 void _X_COLD
    262 SRepXGetFeedbackControl(ClientPtr client, int size,
    263                         xGetFeedbackControlReply * rep)
    264 {
    265     swaps(&rep->sequenceNumber);
    266     swapl(&rep->length);
    267     swaps(&rep->num_feedbacks);
    268     WriteToClient(client, size, rep);
    269 }
    270 
    271 /***********************************************************************
    272  *
    273  * Get the feedback control state.
    274  *
    275  */
    276 
    277 int
    278 ProcXGetFeedbackControl(ClientPtr client)
    279 {
    280     int rc, total_length = 0;
    281     char *buf, *savbuf;
    282     DeviceIntPtr dev;
    283     KbdFeedbackPtr k;
    284     PtrFeedbackPtr p;
    285     IntegerFeedbackPtr i;
    286     StringFeedbackPtr s;
    287     BellFeedbackPtr b;
    288     LedFeedbackPtr l;
    289     xGetFeedbackControlReply rep;
    290 
    291     REQUEST(xGetFeedbackControlReq);
    292     REQUEST_SIZE_MATCH(xGetFeedbackControlReq);
    293 
    294     rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
    295     if (rc != Success)
    296         return rc;
    297 
    298     rep = (xGetFeedbackControlReply) {
    299         .repType = X_Reply,
    300         .RepType = X_GetFeedbackControl,
    301         .sequenceNumber = client->sequence,
    302         .length = 0,
    303         .num_feedbacks = 0
    304     };
    305 
    306     for (k = dev->kbdfeed; k; k = k->next) {
    307         rep.num_feedbacks++;
    308         total_length += sizeof(xKbdFeedbackState);
    309     }
    310     for (p = dev->ptrfeed; p; p = p->next) {
    311         rep.num_feedbacks++;
    312         total_length += sizeof(xPtrFeedbackState);
    313     }
    314     for (s = dev->stringfeed; s; s = s->next) {
    315         rep.num_feedbacks++;
    316         total_length += sizeof(xStringFeedbackState) +
    317             (s->ctrl.num_symbols_supported * sizeof(KeySym));
    318     }
    319     for (i = dev->intfeed; i; i = i->next) {
    320         rep.num_feedbacks++;
    321         total_length += sizeof(xIntegerFeedbackState);
    322     }
    323     for (l = dev->leds; l; l = l->next) {
    324         rep.num_feedbacks++;
    325         total_length += sizeof(xLedFeedbackState);
    326     }
    327     for (b = dev->bell; b; b = b->next) {
    328         rep.num_feedbacks++;
    329         total_length += sizeof(xBellFeedbackState);
    330     }
    331 
    332     if (total_length == 0)
    333         return BadMatch;
    334 
    335     buf = (char *) malloc(total_length);
    336     if (!buf)
    337         return BadAlloc;
    338     savbuf = buf;
    339 
    340     for (k = dev->kbdfeed; k; k = k->next)
    341         CopySwapKbdFeedback(client, k, &buf);
    342     for (p = dev->ptrfeed; p; p = p->next)
    343         CopySwapPtrFeedback(client, p, &buf);
    344     for (s = dev->stringfeed; s; s = s->next)
    345         CopySwapStringFeedback(client, s, &buf);
    346     for (i = dev->intfeed; i; i = i->next)
    347         CopySwapIntegerFeedback(client, i, &buf);
    348     for (l = dev->leds; l; l = l->next)
    349         CopySwapLedFeedback(client, l, &buf);
    350     for (b = dev->bell; b; b = b->next)
    351         CopySwapBellFeedback(client, b, &buf);
    352 
    353     rep.length = bytes_to_int32(total_length);
    354     WriteReplyToClient(client, sizeof(xGetFeedbackControlReply), &rep);
    355     WriteToClient(client, total_length, savbuf);
    356     free(savbuf);
    357     return Success;
    358 }